久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

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

瀏覽:156日期:2022-06-28 11:03:47
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, # 高度,下拉顯示的條目數(shù)量 width=20, # 寬度 state=’readonly’, # 設置狀態(tài) normal(可選可輸入)、readonly(只可選)、 disabled cursor=’arrow’, # 鼠標移動時樣式 arrow, circle, cross, plus... font=(’’, 20), # 字體 textvariable=value, # 通過StringVar設置可改變的值 values=values, # 設置下拉框的選項 ) print(combobox.keys()) # 可以查看支持的參數(shù) combobox.pack() win.mainloop()

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

2、綁定選中事件

# -*- encoding=utf-8 -*-import tkinterfrom tkinter import *from tkinter import ttkdef choose(event): # 選中事件 print(’選中的數(shù)據(jù):{}’.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, # 高度,下拉顯示的條目數(shù)量 width=20, # 寬度 state=’normal’, # 設置狀態(tài) normal(可選可輸入)、readonly(只可選)、 disabled cursor=’arrow’, # 鼠標移動時樣式 arrow, circle, cross, plus... font=(’’, 20), # 字體 textvariable=value, # 通過StringVar設置可改變的值 values=values, # 設置下拉框的選項 ) combobox.bind(’<<ComboboxSelected>>’, choose) print(combobox.keys()) # 可以查看支持的參數(shù) combobox.pack() win.mainloop()

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

以上就是Python tkinter之ComboBox(下拉框)的使用簡介的詳細內(nèi)容,更多關(guān)于Python tkinter之ComboBox 下拉框的使用的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 尚志市| 东光县| 运城市| 湖口县| 颍上县| 香格里拉县| 乌拉特前旗| 永春县| 定边县| 临邑县| 胶州市| 兰坪| 江城| 黑龙江省| 宁武县| 通化市| 吉安市| 浮山县| 木里| 池州市| 南澳县| 汪清县| 永寿县| 老河口市| 东阳市| 综艺| 图们市| 陇西县| 万全县| 绍兴县| 库尔勒市| 克什克腾旗| 长岭县| 宁陕县| 奇台县| 桓仁| 闸北区| 河源市| 张北县| 晋州市| 南乐县|