有没有办法让 GUI 中的文本框具有默认文本显示?
我希望文本框有“请设置您想要的文件的路径...... ”但是,当我运行它时 - 它是空白的......
我的代码如下:
path=StringVar()
textEntry=Entry(master,textvariable=path,text='Please set the path of the file you want...')
textEntry.pack()
有没有办法让 GUI 中的文本框具有默认文本显示?
我希望文本框有“请设置您想要的文件的路径...... ”但是,当我运行它时 - 它是空白的......
我的代码如下:
path=StringVar()
textEntry=Entry(master,textvariable=path,text='Please set the path of the file you want...')
textEntry.pack()
这应该演示如何做你想做的事:
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()