3.2、Entry 与变量绑定
# textvariable:指定绑定的变量名称
from Tkinter import *
root = Tk()
e = StringVar()
# 绑定字符串变量 e
entry = Entry(root,textvariable = e)
e.set('input your text here')
entry.pack()
root.mainloop()
#上面的例子中将变量 e 与 Entry 绑定,然后将 e 的值设置为'input your text here',程序运行
时的初始值便设置了。
代码
from tkinter import *
quehui = Tk()
e = StringVar()
quehui_1 = Entry(quehui,
textvariable = e)
e.set('请在这输入文本')
quehui_1.pack()
quehui.mainloop()


浙公网安备 33010602011771号