Adding Widgets

Widgets are standard items for building a graphic user interface using Tkinter.

Menus

Let’s add a menu. You can create a menu bar using the Menu() function. Assign it to an object (eg menubar) and attach it to your main window.

First we need to create the menubar and add it to the window

menubar = Menu(window)

window.config(menu=menubar)

Next create a “File” menu item.

filemenu = Menu(menubar, tearoff=0)

Add menu items to filemenu. Use the command argument to call the function to carry out the command.

filemenu.add_command(label=”Exit”,                     command=newb)

Add filemenu to the menu bar.

menubar.add_cascade(label=”File”, ...

Get Python Made Easy 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.