Python tkinter之ComboBox(下拉框)的使用簡(jiǎn)介
# -*- encoding=utf-8 -*-import tkinterfrom tkinter import *from tkinter import ttkif __name__ == ’__main__’: win = tkinter.Tk() # 窗口 win.title(’南風(fēng)丶輕語(yǔ)’) # 標(biāo)題 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’, # 設(shè)置狀態(tài) normal(可選可輸入)、readonly(只可選)、 disabled cursor=’arrow’, # 鼠標(biāo)移動(dòng)時(shí)樣式 arrow, circle, cross, plus... font=(’’, 20), # 字體 textvariable=value, # 通過(guò)StringVar設(shè)置可改變的值 values=values, # 設(shè)置下拉框的選項(xiàng) ) print(combobox.keys()) # 可以查看支持的參數(shù) combobox.pack() win.mainloop()
# -*- 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(’南風(fēng)丶輕語(yǔ)’) # 標(biāo)題 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’) # 默認(rèn)選中CCC==combobox.current(2) values = [’AAA’, ’BBB’, ’CCC’, ’DDD’] combobox = ttk.Combobox( master=win, # 父容器 height=10, # 高度,下拉顯示的條目數(shù)量 width=20, # 寬度 state=’normal’, # 設(shè)置狀態(tài) normal(可選可輸入)、readonly(只可選)、 disabled cursor=’arrow’, # 鼠標(biāo)移動(dòng)時(shí)樣式 arrow, circle, cross, plus... font=(’’, 20), # 字體 textvariable=value, # 通過(guò)StringVar設(shè)置可改變的值 values=values, # 設(shè)置下拉框的選項(xiàng) ) combobox.bind(’<<ComboboxSelected>>’, choose) print(combobox.keys()) # 可以查看支持的參數(shù) combobox.pack() win.mainloop()
以上就是Python tkinter之ComboBox(下拉框)的使用簡(jiǎn)介的詳細(xì)內(nèi)容,更多關(guān)于Python tkinter之ComboBox 下拉框的使用的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. web下載文件和跳轉(zhuǎn)的方法2. ASP中常用的22個(gè)FSO文件操作函數(shù)整理3. PHP函數(shù)原理理解詳談4. React+umi+typeScript創(chuàng)建項(xiàng)目的過(guò)程5. SharePoint Server 2019新特性介紹6. JSP數(shù)據(jù)交互實(shí)現(xiàn)過(guò)程解析7. Vue+elementUI下拉框自定義顏色選擇器方式8. ASP的Global.asa文件技巧用法9. ASP中if語(yǔ)句、select 、while循環(huán)的使用方法10. JSP頁(yè)面實(shí)現(xiàn)驗(yàn)證碼校驗(yàn)功能
