entey输入框验证
tkinter 输入框验证如何实现只能输入数字和空格。 from tkinter import *def test(content):
for i in content:
if not i.isdigit() and i != " ":
return False
else:
return True
def main():
root = Tk()
v = StringVar()
test_cmd = root.register(test)
e = Entry(root,
textvariable=v,
validate='key',
validatecommand=(test_cmd, '%P')
)
e.pack()
mainloop()
if __name__ == '__main__':
main()
页:
[1]