在tkinter Entry小部件中交互式验证内容的推荐技术是什么?
我已经阅读了关于使用validate=True和的帖子validatecommand=command,并且看起来这些功能受限于它们在validatecommand命令更新Entry小部件的值时被清除的事实.
鉴于这种行为,我们应该绑定的KeyPress,Cut以及Paste事件和监视/更新我们的Entry小部件的价值,通过这件事情?(以及我可能错过的其他相关事件?)
或者我们是否应该完全忘记交互式验证并仅对FocusOut事件进行验证?
我需要将Entry小部件中的值限制为仅限数字.我实施的方式是:
import numpy as np
from Tkinter import *;
import tkMessageBox;
class window2:
def __init__(self,master1):
self.panel2=Frame(master1)
self.panel2.grid()
self.button2=Button(self.panel2,text="Quit",command=self.panel2.quit)
self.button2.grid()
self.text1=Entry(self.panel2)
self.text1.grid()
self.text1.bind('<KeyPress>', self.keybind1)
self.text1.focus()
def keybind1 (self,event):
if event.int in np.linspace(0,9,10):
print event.int
root1=Tk()
window2(root1)
root1.mainloop()
Run Code Online (Sandbox Code Playgroud)
我不断收到Event实例没有属性'int'的错误消息.我该怎么办?