[Tutor] Creating menu shortcut key bindings
David
bouncingcats at gmail.com
Thu Jun 1 07:35:26 EDT 2023
On Thu, 1 Jun 2023 at 04:16, Phil <phillor9 at gmail.com> wrote:
> What I have is a file menu with open and exit options that I've created
> with pygubu, which works perfectly. Now I'm trying to add a shortcut key
> (ctl + o) to open a file.
> # Bind the shortcut key to the menu item
> self.mainwindow.bind('<Control-o>', lambda event: open_menu_item.invoke()) # no error here
Hi,
Your '<Control-o>' is what Tk calls an event sequence [1].
Your event sequence does not specify any event type [2].
Some event sequences allow the event type to be omitted
for brevity. For example [3]:
'x' is the same as '<KeyPress-x>'
However, I suspect that what you have might not be recognised.
Looking at working code I have here (without actually
testing what you have) I see that I have:
'<Control-KeyPress-o>'
Maybe try that.
[1] https://tkdocs.com/shipman/event-sequences.html
[2] https://tkdocs.com/shipman/event-types.html
[3] https://tkdocs.com/shipman/event-modifiers.html
More information about the Tutor
mailing list