The tkinter menu is a top-level pulldown menu. They are shown just under the title bar, as you’d expect from traditional gui apps.
The menu can have multiple sub menus and each sub menu can contain items. Menu items can be associated with callback methods, meaning when you click them a Python method is called.
Related course: Python Desktop Apps with Tkinter
Example
Introduction
Adding a menu is very straightforward, but it can be a bit confusing if it’s the first time you’re doing it. First create the top menu with these lines:
1 | self.master = master |
Then you can add menus to this menu:
1 | fileMenu = Menu(menu) |
Each of those sub menus can have items:
1 | fileMenu.add_command(label="Item") |
Menu items can be clickable, you can specify the callback method in the same way as buttons (command=). The click will then call a Python method.
tkinter menu example
The menu example below adds a menu to a basic tkinter window. It has one clickable menu item but shows a complete menu.
1 | from tkinter import * |