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.
To bind the <Enter> key with an event in Tkinter window, we can use bind('<Return>', callback) by specifying the key and the callback function as the arguments. Once we bind the key to an event, we can get full control over the events.
The bind() method of Python's socket class assigns an IP address and a port number to a socket instance. The bind() method is used when a socket needs to be made a server socket. As server programs listen on published ports, it is required that a port and the IP address to be assigned explicitly to a server socket.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With