Menus – Intro To Tkinter 9

In this video we’ll look at the Menu Widget for Tkinter and Python.

Menus are super important for any app. They go at the top of your app.

If you want a professional looking app, you’ll almost certainly want a menu.

Python Code: menus.py
(Github Code)

from tkinter import *

root = Tk()
root.title("Menus - Intro To Tkinter")
root.iconbitmap('images/tkinter.ico')
root.geometry('600x400')

def thing(whatever):
	my_label.config(text=whatever)

# Create our main menu
my_menu = Menu(root)

# Create a category item for your menu
file_menu = Menu(my_menu, tearoff=0)
my_menu.add_cascade(label="File", menu=file_menu)

# Add sub-items to our File_Menu 
file_menu.add_command(label="New", command=lambda: thing("New"))
file_menu.add_command(label="Open", command=lambda: thing("Open"))
file_menu.add_command(label="Save", command=lambda: thing("Save"))
# Add a separator
file_menu.add_separator()
file_menu.add_command(label="Exit", command=root.quit)

# Add another Category Item
edit_menu = Menu(my_menu, tearoff=1)
my_menu.add_cascade(label="Edit", menu=edit_menu)

# Add sub item to edit menu
edit_menu.add_command(label="Cut", command=lambda: thing("Cut"))
edit_menu.add_command(label="Copy", command=lambda: thing("Copy"))
edit_menu.add_command(label="Paste", command=lambda: thing("Paste"))
edit_menu.add_checkbutton(label="Checkbox", command=lambda: thing("Check"))
edit_menu.add_radiobutton(label="RadioButton 1", command=lambda: thing("Radio 1"))
edit_menu.add_radiobutton(label="RadioButton 2", command=lambda: thing("Radio 2"))






# Initialize the menu
root.config(menu=my_menu)

my_label = Label(root, text="Select From Menu Above", font=("Helvetica", 24))
my_label.pack(pady=100)





root.mainloop()



John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of the first dot com boom. After that he developed the award-winning Submission-Spider search engine submission software that's been used by over 3 million individuals, businesses, and governments in over 42 countries. He's written several Amazon #1 best selling books on coding, and runs a popular Youtube coding channel.

View all posts

Add comment

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of...