I have a question:
When binding a function in tkinter, there are many ways to do it. Two of the ways are:
# Method 1
root.bind('<Control-n>', ExampleFunction)
# Method 2
root.bind('<Control-Key-n>', ExampleFunction)
What would be the difference between Control-n and Control-Key-n?
Functionally, there is no difference.
Control-Key-n
is an event specifier consisting of
Control
(the control key was held down when the event occurred.)Key
(short for KeyPress
)n
(specifically, the n
key was pressed).From man n bind
:
If a keysym detail is given, then the type field may be omitted; it will default to KeyPress. For example, <Control-comma> is equivalent to <Control-KeyPress-comma>.
So <Control-n>
is just an abbreviated form of <Control-Key-n>
(which itself is an abbreviated form of <Control-KeyPress-n>
): n
alone is equivalent to Key-n
.