您当前的位置:首页 > IT编程 > python
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:Python tkinter之ComboBox(下拉框)的使用简介

51自学网 2021-10-30 23:00:27
  python
这篇教程Python tkinter之ComboBox(下拉框)的使用简介写得很实用,希望能帮到您。

1、ComboBox的基础属性

# -*- encoding=utf-8 -*-import tkinterfrom tkinter import *from tkinter import ttkif __name__ == '__main__':  win = tkinter.Tk() # 窗口  win.title('南风丶轻语') # 标题  screenwidth = win.winfo_screenwidth() # 屏幕宽度  screenheight = win.winfo_screenheight() # 屏幕高度  width = 600  height = 500  x = int((screenwidth - width) / 2)  y = int((screenheight - height) / 2)  win.geometry('{}x{}+{}+{}'.format(width, height, x, y)) # 大小以及位置  value = StringVar()  value.set('CCC')  values = ['AAA', 'BBB', 'CCC', 'DDD']  combobox = ttk.Combobox(      master=win, # 父容器      height=10, # 高度,下拉显示的条目数量      width=20, # 宽度      state='readonly', # 设置状态 normal(可选可输入)、readonly(只可选)、 disabled      cursor='arrow', # 鼠标移动时样式 arrow, circle, cross, plus...      font=('', 20), # 字体      textvariable=value, # 通过StringVar设置可改变的值      values=values, # 设置下拉框的选项      )  print(combobox.keys()) # 可以查看支持的参数  combobox.pack()  win.mainloop()

2、绑定选中事件

# -*- encoding=utf-8 -*-import tkinterfrom tkinter import *from tkinter import ttkdef choose(event):  # 选中事件  print('选中的数据:{}'.format(combobox.get()))  print('value的值:{}'.format(value.get()))if __name__ == '__main__':  win = tkinter.Tk() # 窗口  win.title('南风丶轻语') # 标题  screenwidth = win.winfo_screenwidth() # 屏幕宽度  screenheight = win.winfo_screenheight() # 屏幕高度  width = 600  height = 500  x = int((screenwidth - width) / 2)  y = int((screenheight - height) / 2)  win.geometry('{}x{}+{}+{}'.format(width, height, x, y)) # 大小以及位置  value = StringVar()  value.set('CCC') # 默认选中CCC==combobox.current(2)  values = ['AAA', 'BBB', 'CCC', 'DDD']  combobox = ttk.Combobox(      master=win, # 父容器      height=10, # 高度,下拉显示的条目数量      width=20, # 宽度      state='normal', # 设置状态 normal(可选可输入)、readonly(只可选)、 disabled      cursor='arrow', # 鼠标移动时样式 arrow, circle, cross, plus...      font=('', 20), # 字体      textvariable=value, # 通过StringVar设置可改变的值      values=values, # 设置下拉框的选项      )  combobox.bind('<<ComboboxSelected>>', choose)  print(combobox.keys()) # 可以查看支持的参数  combobox.pack()  win.mainloop()

以上就是Python tkinter之ComboBox(下拉框)的使用简介的详细内容,更多关于Python tkinter之ComboBox 下拉框的使用的资料请关注51zixue.net其它相关文章!


python批量提取图片信息并保存的实现
解决pycharm修改代码后第一次运行不生效的问题
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。