Sunday 29 November 2015

Drop Down Menus



The next code is a simple example of how to make appear menus with Tkinter:

from Tkinter import *
def dns():

    pass
root = Tk()

menu_01 = Menu(root)
root.config(menu = menu_01)
# -- Going inside another menu -- #
sub_menu = Menu(menu_01)
""" Naming the Menu 01 """
menu_01.add_cascade(label = "File", menu = sub_menu)
# --- Adding elements to the menu_01 -- #
sub_menu.add_command(label = "New Project", command = dns)
sub_menu.add_command(label = "New ..."    , command = dns)
""" Separator 01 - Menu 01 """
sub_menu.add_separator()
sub_menu.add_command(label= "Rooms"    , command = dns)
sub_menu.add_command(label = "Roost"    , command = dns)
""" Separator 02 - Menu 01 """
sub_menu.add_separator()
sub_menu.add_command(label = "Exit"    , command = dns)
""" Second Menu : Menu_02 """
edit_menu = Menu(menu_01)
menu_01.add_cascade(label = "Edit", menu = edit_menu)
edit_menu.add_command(label = "Redo", command  = dns)

""" Third Menu : Menu_03 """
risk_menu = Menu(menu_01)
menu_01.add_cascade(label = "Crash", menu = risk_menu)
risk_menu.add_command(label = "Break", command  = dns)
root.mainloop()
And, of course, the result when running the code should be something akin to:






No comments:

Post a Comment