6

I want to bind a Control+1 sequence to a window. widget.bind("<Control-1>", lambda event: someFunction(event)) binds Control + Left Mouse Click. This is the snippet of my code that will use this:

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

I also tried self.master.bind("<Control>-1", lambda event: self.allTypeButtons[1].invoke()), but this gives me: _tkinter.TclError: bad event type or keysym "Control".

Also, self.master.bind("Control-1", lambda event: self.allTypeButtons[1].invoke()) and then pressing Control+1 doesn't invoke the event.

I know that widget.bind("1", lambda event: someFunction(event)) binds 1, widget.bind("<1>", lambda event: someFunction(event)) binds Left Mouse Click, and widget.bind("<Control-h>", lambda event: someFunction(event)) binds Control+h, but how can I incorporate Control+1? Thanks in advance.

Rushy Panchal
  • 16,979
  • 16
  • 61
  • 94

1 Answers1

8

The event name is <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()

I've posted a partial table of event names here.

Community
  • 1
  • 1
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677