serjo
serjo

Reputation: 13

tkinter.menu.config doesn't work for python GUI

I tried to program a GUI in python using tkinter and python3. First I import tkinter and filedialog module, then I create a window that contains text field. The proble occur in the following line, the menu doesn't appear in the window:

MENU = tk.Menu(WIN)
WIN.config(menu=MENU)
fm = tk.Menu(MENU)
fm.add_command(label='Open...', command=do_open)
fm.add_command(label='Save', command=do_save)
fm.add_command(label='Save As...', command=do_saveas)
fm.add_separator()
fm.add_command(label='Quit', command=do_quit)
fm.add_cascade(label='File', menu=fm)

Can anyone help me?

Upvotes: 1

Views: 139

Answers (2)

Daniel Huckson
Daniel Huckson

Reputation: 1227

Here try this.

        MENU = tk.Menu(self)
        self.config(menu=MENU)
        fm = tk.Menu(MENU)
        MENU.add_cascade(label='File', menu=fm)

        fm.add_command(label='Open...', command=do_open)
        fm.add_command(label='Save', command=do_save)
        fm.add_command(label='Save As...', command=do_saveas)
        fm.add_separator()
        fm.add_command(label='Quit', command=do_quit)
        fm.add_cascade(label='File', menu=fm)

Upvotes: 0

Bryan Oakley
Bryan Oakley

Reputation: 385980

You never add the fm menu to MENU.

Change this:

fm.add_cascade(label='File', menu=fm)

... to this:

MENU.add_cascade(label='File', menu=fm)

Upvotes: 1

Related Questions