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

标签 python python-3.x tkinter combobox ttk

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

相关文章:

python - Numpy 一维数组 : Row or Column Matrix by Default?

python - 读取作为 base64 接收的 CSV 文件的内容

python - 无法使用 tkinter 调整图像大小

python - 如何在类中使用 tkinter 的 nametowidget 函数获取小部件名称

python - pytest-mock 补丁上下文管理器在退出时不恢复对象

python 扭曲 : how do use different resource hierarchies for localhost connections?

python - pytest导入错误

python - 如何突出显示文本小部件的当前行?

Python - 从文件夹中读取所有文件(.shp、.dbf、.mxd 等)

python - Airflow 在 Python 运算符之间传递数据帧