Tkinter dropdown Menu with keyboard shortcuts?

Viewed 19583

I would like to have a Dropdown Menu in Tkinter, that includes the shortcut key associated with this command. Is this possible?

How would I also add the underline under a certain character, to allow for Alt-F-S (File->Save)?

3 Answers

In this code press ctrl+e to exit the programmme

from tkinter import *

class MainApp:
    def __init__(self, root):
        self.root = root
        self.menubar = Menu(self.root)
        self.fileMenu = Menu(self.menubar, tearoff=False)
        self.menubar.add_cascade(label="File", menu=self.fileMenu)
        self.fileMenu.add_command(label="Exit", accelerator="Ctrl+E")
        self.root.config(menu=self.menubar)

        self.root.bind_all("<Control-e>", lambda event: self.root.quit())
        self.root.mainloop()


if __name__ == "__main__":
    MainApp(Tk())
Related