Python:有没有一种方法可以使输入字段具有默认值?
有没有办法在GUI中设置一个默认文本显示的文本框 我希望文本框将有“请设置您想要的文件路径…” 但是,当我运行它时,它是空的 我的代码如下:Python:有没有一种方法可以使输入字段具有默认值?,python,tkinter,tkinter-entry,Python,Tkinter,Tkinter Entry,有没有办法在GUI中设置一个默认文本显示的文本框 我希望文本框将有“请设置您想要的文件路径…” 但是,当我运行它时,它是空的 我的代码如下: path=StringVar() textEntry=Entry(master,textvariable=path,text='Please set the path of the file you want...') textEntry.pack() -或- 有用的文件: 这应该演示如何做您想做的事情: import Tkinter
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()
textEntry.insert(0, "Please set the path of the file you want...")
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()