from tkinter import *
root = Tk()
Entry(root).pack()
root.mainloop()
from tkinter import *
root = Tk()
e = StringVar()
entry = Entry(root,textvariable = e)
e.set('input your text here')
entry.pack()
root.mainloop()
在上篇文章中曾用textvariable改变buttun中text值
Entry的另一个比较有用的属性,设置为只读,不允许用户对它的值改变。设置state属性为'readonly'
from tkinter import *
root = Tk()
e = StringVar()
entry = Entry(root,textvariable = e)
e.set('input your text here')
entry.pack()
entry['state'] = 'readonly'
root.mainloop()
Entry的属性值可以使用的也为normal/active/disabled,'readonly'与disabled相似,只不过disabled会是组件变成灰色
from tkinter import *
root = Tk()
e = StringVar()
entry = Entry(root,textvariable = e)
e.set('input your text here')
entry.pack()
#使用*来显示输入的内容,如果喜欢可以改为其它字符
entry['show'] = '*'
#分别使用*#$显示输入的文本内容
for mask in ['*','#','$']:
e = StringVar()
entry = Entry(root,textvariable = e)
e.set('password')
entry.pack()
entry['show'] = mask
root.mainloop()