Creating MENU widget in Tkinter
from tkinter import *
root = Tk()
def fruits():
print("This is a fruit!")
def people():
print("This is a person!")
root.geometry("600x200")
root.title("Menus Submenus in Tkinter")
mymenu = Menu(root)
m1 = Menu(mymenu, tearoff=0)
m1.add_command(label="Apple", command=fruits)
m1.add_command(label="banana", command=fruits)
m1.add_separator()
m1.add_command(label="lemon", command=fruits)
m1.add_command(label="guava", command=fruits)
mymenu.add_cascade(label="Fruits", menu=m1)
m2 = Menu(mymenu, tearoff=0)
m2.add_command(label="adam", command=people)
m2.add_command(label="john", command=people)
m2.add_separator()
m2.add_command(label="abdur", command=people)
m2.add_command(label="wahab", command=people)
mymenu.add_cascade(label="People", menu=m2)
root.config(menu=mymenu)
root.mainloop()
Comments
Post a Comment
Write something to CodeWithAbdur!