2013-07-25 154 views
1

有没有一种方法可以在GUI中拥有一个默认文本显示的文本框?Python:有没有办法让Entry字段具有默认值?

我想要的文本框将具有“请设置您想要的文件的路径...” 然而,当我运行它 - 如下是空白......

我的代码:

path=StringVar() 
    textEntry=Entry(master,textvariable=path,text='Please set the path of the file you want...') 
    textEntry.pack() 

回答

1

这应该说明如何做你想要的:

import Tkinter as tk 

root = tk.Tk() 

entry = tk.Entry(root, width=40) 
entry.pack() 
# Put text in the entrybox with the insert method. 
# The 0 means "at the begining". 
entry.insert(0, 'Please set the path of the file you want...') 

text = tk.Text(root, width=45, height=5) 
text.pack() 
# Textboxes also have an insert. 
# However, since they have a height and a width, you need to 
# put 0.0 to spcify the beginning. That is basically the same as 
# x=0, y=0. 
text.insert(0.0, 'Please set the path of the file you want...') 

root.mainloop() 
1
path.set("Please set the path of the file you want...") 

- 或 -

textEntry.insert(0, "Please set the path of the file you want...") 

USEF UL文件:

相关问题