I am going through the Tk/Tkinter tutorial and
when I try to run the menubar program I get two windows instead of a menubar on one window.

Here is the code:

from tkinter import *
from tkinter import ttk
root = Tk()
root.option_add('*tearOff', FALSE)

win = Toplevel(root)
menubar = Menu(win)
win['menu'] = menubar

menubar = Menu(win)
menu_file = Menu(menubar)
menu_edit = Menu(menubar)
menubar.add_cascade(menu=menu_file, label='File')
menubar.add_cascade(menu=menu_edit, label='Edit')

menu_file.add_command(label='New', command=None)
menu_file.add_command(label='Open...', command=None)
menu_file.add_command(label='Close', command=None)

root.mainloop()

Please let me know what I am doing wrong.

- WolfShield

Too much junk in the code, try it this way ...

from tkinter import *
from tkinter import ttk

root = Tk()
root.option_add('*tearOff', FALSE)

menubar = Menu(root)
root.config(menu=menubar)
menu_file = Menu(menubar)
menu_edit = Menu(menubar)
menubar.add_cascade(menu=menu_file, label='File')
menubar.add_cascade(menu=menu_edit, label='Edit')

menu_file.add_command(label='New', command=None)
menu_file.add_command(label='Open...', command=None)
menu_file.add_command(label='Close', command=None)

root.mainloop()

There are some pretty bad tutorials floating about, which one is this exactly?

I am going through this one: http://www.tkdocs.com/tutorial/

What one would you suggest?

Thank you vegaseat, my program is working right now. Was it the 'Toplevel' that was
creating the second window?

- WolfShield

Just experiment with it!

This is sort of the Bible of Tkinter:
http://infohost.nmt.edu/tcc/help/pubs/tkinter.pdf

However bummer, you have to come up with your own examples and again experiment.

Thanks everyone!

- WolfShield

GUI programming takes a while to get used to. I always hang up on the widget layouts.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.