我想使用一个条目小部件来获取 1 到 9 之间的数字。如果按下任何其他键,我想将其从显示中删除。
def onKeyPress(event):
if event.char in ['1', '2', '3', '4', '5', '6', '7', '8', '9']
...do something
return
# HERE I TRY AND REMOVE AN INVALID CHARACTER FROM THE SCREEN
# at this point the character is:
# 1) visible on the screen
# 2) held in the event
# 3) NOT YET in the entry widgets string
# as the following code shows...
print ">>>>", event.char, ">>>>", self._entry.get()
# it appeARS that the entry widget string buffer is always 1 character behind the event handler
# so the following code WILL NOT remove it from the screen...
self._entry.delete(0, END)
self._entry.insert(0, " ")
# here i bind the event handler
self._entry.bind('<Key>', onKeyPress)
好的,我怎样才能清除屏幕?