2013-07-25 192 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文件:

相關問題