簡體   English   中英

ttk.combobox:如何在框中放置默認文本?

[英]ttk.combobox: How to place a default text inside the box?

嘗試使用textvariableinsert但它沒有用。 我希望實現的是:

但是,當您尚未選擇任何內容時,文本不會作為值存儲在組合框中,而只是默認文本。

到目前為止,這是我的代碼:

root = Tk()
root.geometry('800x600')
root.title('CSSD')
topFrame=Frame(root,width=800,height=150,pady=10,padx=250)
area=Label(topFrame,text='CSSD')
area.config(font=("Courier", 100))
frame=Frame(root,highlightbackground="black", highlightcolor="black", highlightthickness=1, width=100, height=100, bd= 0)
frame.place(relx=.5, rely=.5, anchor="center")
username = Label(frame, text='User Name')
username.config(font='Arial',width=15)
password = Label(frame, text='Password')
password.config(font='Arial',width=15)
enteruser = Entry(frame, textvariable=StringVar(),font=large_font)
enterpass = Entry(frame, show='*', textvariable=StringVar(),font=large_font)


combo=ttk.Combobox(frame)
combo['values']=('Clinic 1','Clinic 2','Clinic 3','Clinic 4','Clinic 5','Clinic 6','Clinic 10','Clinic 11','OB')
combo.state(['readonly'])
combo.grid(row=0,sticky=NW)


topFrame.grid(row=0,sticky=EW)
area.grid(row=0,columnspan=300)
username.grid(row=1, sticky=E)
enteruser.grid(row=1, column=1)
password.grid(row=2, sticky=E)
enterpass.grid(row=2, column=1)

您可以像這樣使用set方法:

combo.set('default')

以防萬一沒有人提到它,這是另一種選擇。

method = StringVar(value='default') 
choosen = ttk.Combobox(root, width = 14, textvariable = method, )

這也適用於Checkbutton

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM