Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bind Ctrl+/ in python tkinter?

<Control-Shift-Key-0>
<Control-Key-plus>

works but

<Control-Key-/>

doesn't.

I am unable to bind ctrl + / in python. Is there any documentation of all the possible keys?

like image 450
Abhishek Kumar Avatar asked Apr 18 '13 11:04

Abhishek Kumar


People also ask

How does bind work in Tkinter?

In Tkinter, bind is defined as a Tkinter function for binding events which may occur by initiating the code written in the program and to handle such events occurring in the program are handled by the binding function where Python provides a binding function known as bind() where it can bind any Python methods and ...

What is bind () in Python?

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.

How do I bind the Enter key to a function in Tkinter?

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.

How do you bind a key to a button in Python?

Practical Data Science using Python Tkinter provides a way to bind the widget to perform certain operations. These operations are defined in a function that can be called by a particular widget. The bind(<button>, function()) method is used to bind the keyboard key to handle such operations.


2 Answers

Use <Control-slash>:

def quit(event):
    print "you pressed control-forwardslash"
    root.quit()

root = tk.Tk()
root.bind('<Control-slash>', quit)      # forward-slash
# root.bind('<Control-backslash>', quit)  # backslash
root.mainloop()

I don't have a link to a complete list of these event names. Here is a partial list I've collected:

| event                 | name                  |
| Ctrl-c                | Control-c             |
| Ctrl-/                | Control-slash         |
| Ctrl-\                | Control-backslash     |
| Ctrl+(Mouse Button-1) | Control-1             |
| Ctrl-1                | Control-Key-1         |
| Enter key             | Return                |
|                       | Button-1              |
|                       | ButtonRelease-1       |
|                       | Home                  |
|                       | Up, Down, Left, Right |
|                       | Configure             |
| window exposed        | Expose                |
| mouse enters widget   | Enter                 |
| mouse leaves widget   | Leave                 |
|                       | Key                   |
|                       | Tab                   |
|                       | space                 |
|                       | BackSpace             |
|                       | KeyRelease-BackSpace  |
| any key release       | KeyRelease            |
| escape                | Escape                |
|                       | F1                    |
|                       | Alt-h                 |
like image 92
unutbu Avatar answered Sep 18 '22 13:09

unutbu


Here is a list of all the tk keysysm codes: https://www.tcl.tk/man/tcl8.6/TkCmd/keysyms.htm

The two I was looking for was <Win_L> and <Win_R>.

like image 34
Von Pittman Avatar answered Sep 20 '22 13:09

Von Pittman