Control + Number Tkinter绑定

时间:2013-06-21 17:55:08

标签: python graphics tkinter

我想将 Control + 1 序列绑定到窗口。 widget.bind("<Control-1>", lambda event: someFunction(event))绑定 Control +鼠标左键单击。这是我的代码片段,将使用此代码:

self.master.bind("<Control-1>", lambda event: self.allTypeButtons[1].invoke())
self.master.bind("<Control-2>", lambda event: self.allTypeButtons[2].invoke())
self.master.bind("<Control-3>", lambda event: self.allTypeButtons[3].invoke())
# self.allTypeButtons is a dictionary with Radiobuttons as its values

我也试过self.master.bind("<Control>-1", lambda event: self.allTypeButtons[1].invoke()),但这给了我:_tkinter.TclError: bad event type or keysym "Control"

此外,self.master.bind("Control-1", lambda event: self.allTypeButtons[1].invoke())然后按 Control + 1 不会调用该事件。

我知道widget.bind("1", lambda event: someFunction(event))绑定 1 widget.bind("<1>", lambda event: someFunction(event))绑定鼠标左键单击widget.bind("<Control-h>", lambda event: someFunction(event))绑定 Control + h ,但我怎样才能合并 Control + 1 ?提前谢谢。

1 个答案:

答案 0 :(得分:7)

活动名称为<Control-Key-1>

import Tkinter as tk
def quit(event):
    print("You pressed Control-Key-1")
    root.quit()

root = tk.Tk()
root.bind('<Control-Key-1>', quit)
root.mainloop()

我在这里发布了partial table of event names