• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Python tkinter之ComboBox(下拉框)的使用简介

python 搞代码 4年前 (2022-01-07) 102次浏览 已收录 0个评论
文章目录[隐藏]

这篇文章主要介绍了Python tkinter之ComboBox(下拉框)的使用简介,帮助大家更好的理解和使用python,感兴趣的朋友可以了解下

1、ComboBox的基础属性

 # -*- encoding=utf-8 -*- import tkinter from tkinter import * from tkinter import ttk 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') 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 tkinter from tkinter import * from tkinter import ttk def 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) va<b style="color:transparent">来源gao@!dai!ma.com搞$$代^@码网</b>lues = ['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('<>', choose) print(combobox.keys()) # 可以查看支持的参数 combobox.pack() win.mainloop()

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

以上就是Python tkinter之ComboBox(下拉框)的使用简介的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Python tkinter之ComboBox(下拉框)的使用简介
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址