A menu bar

The top menu bar of an application usually just contains other menus, such as file and edit. These are known as "cascades" in Tkinter, and are essentially a menu inside a menu. This may be confusing at first, so let's begin with a very simple example to demonstrate the difference between a menu and a cascade.

Create a new Python file called menu.py and add the following code:

import tkinter as tkwin = tk.Tk()win.geometry('400x300')lab = tk.Label(win, text="Demo application")menu = tk.Menu(win)

After importing Tkinter and creating a main window and Label, we make our first Menu widget. As with a lot of widgets, the first argument needed is the master, or parent, in which the widget will be drawn. We draw this menu in our main window ...

Get Tkinter GUI Programming by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.