Advertisement
Felanpro

create dropdown menu

Aug 15th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. from tkinter import*
  2.  
  3. def add_button():
  4.     button1 = Button(text = "Button")
  5.     button1.pack()
  6.  
  7. def add_text():
  8.     label1 = Label(text = "Text")
  9.     label1.pack()
  10.  
  11. root = Tk()
  12. root.title("Application")
  13. root.resizable(width=False, height=False) #Not resizable<--!-->
  14. root.geometry("500x300") #Set width and height<--!-->
  15.  
  16. menu1 = Menu(root)
  17.  
  18. root.config(menu = menu1)
  19.  
  20. subMenu1 = Menu(menu1)
  21.  
  22. menu1.add_cascade(label = "Add", menu = subMenu1) #Add subMenu1 as dropdown menu on main menu1.
  23.  
  24. subMenu1.add_command(label = "Button", command = add_button) #Add item to subMenu1 and command.
  25. subMenu1.add_separator()
  26. subMenu1.add_command(label = "Text", command = add_text)
  27.  
  28. root.mainloop() #When mainloop is breaked the program ends.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement