954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Menubar Problem

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

WolfShield
Posting Whiz in Training
236 posts since Oct 2010
Reputation Points: 28
Solved Threads: 4
 

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()
vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

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

HiHe
Posting Whiz in Training
236 posts since Oct 2008
Reputation Points: 137
Solved Threads: 22
 

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

WolfShield
Posting Whiz in Training
236 posts since Oct 2010
Reputation Points: 28
Solved Threads: 4
 

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.

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

Thanks everyone!

- WolfShield

WolfShield
Posting Whiz in Training
236 posts since Oct 2010
Reputation Points: 28
Solved Threads: 4
 

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

HiHe
Posting Whiz in Training
236 posts since Oct 2008
Reputation Points: 137
Solved Threads: 22
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: