【发布时间】:2023-03-18 19:45:01
【问题描述】:
我正在尝试在单击后取消绑定/禁用键,并在 2 秒后恢复其功能。但我无法弄清楚解除绑定的代码。绑定在窗口上。这是我到目前为止尝试过的代码:
self.choiceA = self.master.bind('a', self.run1) #bind key "a" to run1
def run1(self, event=None):
self.draw_confirmation_button1()
self.master.unbind('a', self.choiceA) #try1: use "unbind", doesn't work
self.choiceA.configure(state='disabled') #try2: use state='disabled', doesn't't work, I assume it only works for button
self.master.after(2000, lambda:self.choiceA.configure(state="normal"))
另外,如何在 2s 后重新启用密钥?
非常感谢!
【问题讨论】:
标签: python events tkinter bind unbind