Python tkinter之ComboBox(下拉框)的使用簡介
更新時間:2021年02月05日 17:22:52 作者:南風(fēng)丶輕語
這篇文章主要介紹了Python tkinter之ComboBox(下拉框)的使用簡介,幫助大家更好的理解和使用python,感興趣的朋友可以了解下
1、ComboBox的基礎(chǔ)屬性
# -*- encoding=utf-8 -*- import tkinter from tkinter import * from tkinter import ttk if __name__ == '__main__': win = tkinter.Tk() # 窗口 win.title('南風(fēng)丶輕語') # 標(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)移動時樣式 arrow, circle, cross, plus... font=('', 20), # 字體 textvariable=value, # 通過StringVar設(shè)置可改變的值 values=values, # 設(shè)置下拉框的選項 ) print(combobox.keys()) # 可以查看支持的參數(shù) combobox.pack() win.mainloop()
2、綁定選中事件
# -*- encoding=utf-8 -*- import tkinter from tkinter import * from tkinter import ttk def choose(event): # 選中事件 print('選中的數(shù)據(jù):{}'.format(combobox.get())) print('value的值:{}'.format(value.get())) if __name__ == '__main__': win = tkinter.Tk() # 窗口 win.title('南風(fēng)丶輕語') # 標(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)移動時樣式 arrow, circle, cross, plus... font=('', 20), # 字體 textvariable=value, # 通過StringVar設(shè)置可改變的值 values=values, # 設(shè)置下拉框的選項 ) combobox.bind('<<ComboboxSelected>>', choose) print(combobox.keys()) # 可以查看支持的參數(shù) combobox.pack() win.mainloop()
以上就是Python tkinter之ComboBox(下拉框)的使用簡介的詳細內(nèi)容,更多關(guān)于Python tkinter之ComboBox 下拉框的使用的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Django的restframework接口框架自定義返回數(shù)據(jù)格式的示例詳解
這篇文章主要介紹了Django的restframework接口框架自定義返回數(shù)據(jù)格式,本文介紹了通過Django的restframework接口框架自定義Response返回對象來自定義返回數(shù)據(jù)格式,本文通過示例代碼給大家介紹的非常詳細,需要的朋友可以參考下2022-07-07Python word2vec訓(xùn)練詞向量實例分析講解
這篇文章主要介紹了Python word2vec訓(xùn)練詞向量實例分析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2022-12-12python腳本請求數(shù)量達到上限,http請求重試問題
這篇文章主要介紹了python腳本請求數(shù)量達到上限,http請求重試問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-06-06python機器學(xué)習(xí)高數(shù)篇之泰勒公式
這篇文章主要介紹了python機器學(xué)習(xí)高數(shù)篇之函數(shù)極限和導(dǎo)數(shù),本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-08-08Python統(tǒng)計單詞出現(xiàn)的次數(shù)
最近經(jīng)理交給我一項任務(wù),統(tǒng)計一個文件中每個單詞出現(xiàn)的次數(shù),列出出現(xiàn)頻率最多的5個單詞。本文給大家?guī)砹藀ython 統(tǒng)計單詞次數(shù)的思路解析,需要的朋友參考下吧2018-04-04Python結(jié)合ImageMagick實現(xiàn)多張圖片合并為一個pdf文件的方法
這篇文章主要介紹了Python結(jié)合ImageMagick實現(xiàn)多張圖片合并為一個pdf文件的方法,結(jié)合實例形式分析了Python將圖片文件轉(zhuǎn)換為pdf文件的相關(guān)操作技巧,需要的朋友可以參考下2018-04-04