gpt4 book ai didi

python - ttk.组合框 : How to place a default text inside the box?

转载 作者:行者123 更新时间:2023-12-05 01:18:35 26 4
gpt4 key购买 nike

尝试使用 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')

关于python - ttk.组合框 : How to place a default text inside the box?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44711792/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com