tkinter menu bar
Python hosting: Host, run, and code Python in the cloud!
The Tkinter toolkit comes with all the basic widgets to create graphical applications. Almost every app has a main menu. As expected, Tkinter supports adding a main menu to your application window.
The screenshot below demonstrates a Tkinter based menu:

Related course
Tkinter menubar
You can create a simle menu with Tkinter using the code below. Every option (new, open, save.. ) should have its own callback.
from Tkinter import * |
We create the menubar with the call:
|
where root is a Tk() object.
A menubar may contain zero or more submenus such as the file menu, edit menu, view menu, tools menu etcetera.
A submenu can be created using the same Menu() call, where the first argument is the menubar to attach to.
|
Individual options can be added to these submenus using the add_command() method:
|
In the example we created the callback function donothing() and linked every command to it for simplicity. An option is added using the add_comment() function. We call add_cascade() to add this menu list to the specific list.
If you are new to programming Tkinter, I highly recommend this course.
Leave a Reply:
does not work on mac
no one help?
hi, Tk should work on mac os x. see this link https://www.python.org/download/mac/tcltk/
or video of install here https://www.youtube.com/watch?v=yoMXGKpESdc
This link may also be useful: http://stackoverflow.com/questions/15057166/import-tkinter-fails-with-python-2-7-3-mac-osx-10-8-2
Alternatively, you could use the WxPython or QT module to create a GUI (also tutorials on this site)
i'm trying to add something myself and its not working:
Hi, the last line should be:
Full code: