In this video we’ll learn how to use Menu Button popups for Tkinter.

Menu buttons are similar to the regular Menu bars we looked at several videos ago…

Except they aren’t bars, they’re buttons located anywhere you want! Click them and a menu pops up!

Python Code: menu_buttons.py
(Github Code)

from tkinter import *

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

def thing(item):
	my_label.config(text=f'You Cliked {item}')


# Create a menu button
my_menu = Menubutton(root, text="File Menu", relief="raised") # flat, sunken, raised, groove, ridge
my_menu.pack(pady=100)

# Define the menu
my_menu.menu = Menu(my_menu, tearoff=0)
my_menu["menu"] = my_menu.menu

# Add sub items
my_menu.menu.add_command(label="New", command=lambda: thing("New")) 
my_menu.menu.add_checkbutton(label="Open", command=lambda: thing("Open"))
my_menu.menu.add_radiobutton(label="Save", command=lambda: thing("Save"))
my_menu.menu.add_radiobutton(label="Save As", command=lambda: thing("Save As"))


# Add a label
my_label = Label(root, text="", font=("Helvetica", 24))
my_label.pack()

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

Your email address will not be published. Required fields are marked *

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...