views:

103

answers:

1

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

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

+2  A: 
import Tkinter
import sys

class App(Tkinter.Tk):
    def __init__(self):
        Tkinter.Tk.__init__(self)
        menubar = Tkinter.Menu(self)
        fileMenu = Tkinter.Menu(menubar, tearoff=False)
        menubar.add_cascade(label="File",underline=0, menu=fileMenu)
        fileMenu.add_command(label="Exit", underline=1, 
                             command=quit, accelerator="Ctrl+Q")
        self.config(menu=menubar)

        self.bind_all("<Control-q>", self.quit)

    def quit(self, event):
        print "quitting..."
        sys.exit(0)

if __name__ == "__main__":
    app=App()
    app.mainloop()
Bryan Oakley
Thank you, how did you find that?
CMC
@CMC: I didn't find it, I know it. I've been doing Tk development with Tcl since '95 and translating that knowledge to python is very straight-forward.
Bryan Oakley
CMC
@CMC: are you wanting to underline more than one character? The underline option (as in the example) allows you to only underline a single character.
Bryan Oakley
Ah, I see now, I was interpreting the underline option as a boolean value...thanks.
CMC