6

我想将一个Control+1序列绑定到一个窗口。widget.bind("<Control-1>", lambda event: someFunction(event))绑定Control + Left Mouse Click。这是我的代码片段,将使用它:

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))绑定1widget.bind("<1>", lambda event: someFunction(event))绑定Left Mouse Clickwidget.bind("<Control-h>", lambda event: someFunction(event))绑定Control+h,但我该如何合并Control+1?提前致谢。

4

1 回答 1

8

事件名称是<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()

我在这里发布了部分事件名称表

于 2013-06-21T18:00:32.583 回答