ComboBox怎么在Python項(xiàng)目中使用?相信很多沒有經(jīng)驗(yàn)的人對(duì)此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。
# -*- encoding=utf-8 -*- import tkinter from tkinter import * from tkinter import ttk 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') 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, # 通過StringVar設(shè)置可改變的值 values=values, # 設(shè)置下拉框的選項(xiàng) ) print(combobox.keys()) # 可以查看支持的參數(shù) combobox.pack() win.mainloop()
# -*- 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)丶輕語(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, # 通過StringVar設(shè)置可改變的值 values=values, # 設(shè)置下拉框的選項(xiàng) ) combobox.bind('<<ComboboxSelected>>', choose) print(combobox.keys()) # 可以查看支持的參數(shù) combobox.pack() win.mainloop()
看完上述內(nèi)容,你們掌握ComboBox怎么在Python項(xiàng)目中使用的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
當(dāng)前標(biāo)題:ComboBox怎么在Python項(xiàng)目中使用-創(chuàng)新互聯(lián)
文章鏈接:http://jinyejixie.com/article18/dphcgp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、外貿(mào)建站、電子商務(wù)、網(wǎng)站導(dǎo)航、自適應(yīng)網(wǎng)站、域名注冊(cè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容