[Tutor] Tkinter Menus

Jorge Louis De Castro jorge at bcs.org.uk
Tue Aug 9 12:18:54 CEST 2005


Hello,

I'm having this issue with Tkinter. I have a frame with all my buttons, 
checkboxes et al, and all is working fine. I want to add menus and added the 
following to my frame (fCanvas) code:

    # create a toplevel menu
    menu = Menu(fCanvas)
    fCanvas.config(menu=menu)
    # create a pulldown menu, and add it to the menu bar
    filemenu = Menu(menu, tearoff=0)
    filemenu.add_command(label="Open", command=self.doBrowse)
    filemenu.add_separator()
    filemenu.add_command(label="Exit", command=self.doQuit)
    menu.add_cascade(label="File", menu=filemenu)
    # create analyze pulldown menu
    analyzemenu = Menu(menu, tearoff=0)
    analyzemenu.add_command(label="Start", command=self.doStart)
    analyzemenu.add_command(label="Reset", command=self.doReset)
    menu.add_cascade(label="Analyze", menu=analyzemenu)
    # create about pulldown menu
    aboutmenu = Menu(menu, tearoff=0)
    menu.add_cascade(label="About", menu=aboutmenu)

Gives me the error:
Traceback (most recent call last):
  File "C:\Workplace\python\im_logparser\msn_parser_gui.py", line 203, in ?
    myApp = LogAnalyzerGUI()
  File "C:\Workplace\python\im_logparser\msn_parser_gui.py", line 11, in 
__init__
    self.buildUI()
  File "C:\Workplace\python\im_logparser\msn_parser_gui.py", line 35, in 
buildUI
    fCanvas.config(menu=menu)
  File "C:\Python24\Lib\lib-tk\Tkinter.py", line 1139, in configure
    return self._configure('configure', cnf, kw)
  File "C:\Python24\Lib\lib-tk\Tkinter.py", line 1130, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
TclError: unknown option "-menu"


Unless I replace the menu creation from using my frame to using the root:

root = Tk()
menu = Menu(root)
root.config(menu=menu)

But this obviously creates another window which is not what I want at all. 
Any thoughts?

Chrs
j.


More information about the Tutor mailing list