17
<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?

ZhaoGang
  • 4,491
  • 1
  • 27
  • 39
Abhishek Kumar
  • 179
  • 1
  • 1
  • 10

2 Answers2

57

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                 |
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
  • Then how to add backward-slash as binding? – Abhishek Kumar Apr 18 '13 at 12:17
  • 1
  • @unutbu I realised that the problem is something else. Command+Down triggers within tkinter just the Down arrow, however using Command+Down selects the box below instead of the text area which makes it possible to select items from a list. So I guess I need to find out how to select that area without the command key. Any ideas? – Joop Feb 11 '17 at 20:20
  • 1
    @Joop: I'm not sure but I think the answer is to subclass the widget and override the `Command+Down` binding. See http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm (search for the word "override"). – unutbu Feb 11 '17 at 20:28
  • Thank you for your help. I did not manage to fix it yet. If you have by any chance time to look at it, I tried to clearly formulate my question here: http://stackoverflow.com/q/42181333/3972558 – Joop Feb 11 '17 at 21:17
  • Apparently `` is not correct, and neither is `Alt-k`. It must be exactly `` to control the Alt-K keystroke. Just wow... I hadn't stumble upon the correct arrangement until I read this post. – bgStack15 Jun 13 '19 at 01:26
14

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>.

Von Pittman
  • 181
  • 1
  • 7
  • 1
    This is a very useful resource, used it to find how to bind the release of a Ctrl button. – Siwel Mar 28 '16 at 17:53