Python tkinter之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()
# -*- 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 下拉框的使用的資料請關注好吧啦網其它相關文章!
相關文章:
1. css代碼優化的12個技巧2. .NET SkiaSharp 生成二維碼驗證碼及指定區域截取方法實現3. MyBatis JdbcType 與Oracle、MySql數據類型對應關系說明4. 在JSP中使用formatNumber控制要顯示的小數位數方法5. ASP中if語句、select 、while循環的使用方法6. jsp網頁實現貪吃蛇小游戲7. CentOS郵件服務器搭建系列—— POP / IMAP 服務器的構建( Dovecot )8. ASP中實現字符部位類似.NET里String對象的PadLeft和PadRight函數9. 存儲于xml中需要的HTML轉義代碼10. 利用CSS制作3D動畫
