menu in python

Solutions on MaxInterview for menu in python by the best coders in the world

showing results for - "menu in python"
Catalina
26 Sep 2017
1from tkinter import *
2from tkinter import messagebox # just for example not necessary
3
4# some example fungtions
5def Res():
6    root.geometry('333x222')
7def B2N():
8    root.geometry('444x444')
9def Full():
10    root.geometry('1000x700')
11def custom_quit():
12    answer=tkinter.messagebox.askokcancel("Are you Sure?","Your Data will be lost if you exit")
13    if (answer):
14        quit()
15        
16#the main window
17root=Tk()
18root.geometry('444x444')
19text=Label(root,text='*my first menu*').pack()
20# the actual menu (used a big example for better understanding of menu and sub-menu)
21menu1=Menu(root)
22root.configure(menu=menu1)
23
24submenu1=Menu(menu1)
25menu1.add_cascade(label='File',menu=submenu1)
26sub2menu=Menu(submenu1)
27sub2menu.add_command(label='Recent')
28sub2menu.add_command(label='Browse')
29
30submenu1.add_command(label='New File')
31submenu1.add_cascade(label='Open File',menu=sub2menu)
32submenu1.add_command(label='Save As')
33submenu1.add_command(label='Print')
34submenu1.add_command(label='Quit', command=custom_quit) # adding command to menu elements
35
36submenu2=Menu(menu1)
37menu1.add_cascade(label='Edit',menu=submenu2)
38submenu2.add_command(label='Undo')
39submenu2.add_cascade(label='Redo')
40submenu2.add_command(label='Cut')
41submenu2.add_command(label='Copy')
42submenu2.add_command(label='Paste')
43submenu2.add_command(label='Select All')
44
45submenu3=Menu(menu1)
46menu1.add_cascade(label='Format',menu=submenu3)
47submenu3.add_command(label='Indent Region')
48submenu3.add_cascade(label='Comment')
49submenu3.add_command(label='All')
50submenu3.add_command(label='Selected')
51submenu3.add_command(label='Format Paragraph')
52
53submenu4=Menu(menu1)
54menu1.add_cascade(label='Run',menu=submenu4)
55submenu4.add_command(label='Python Shell')
56submenu4.add_cascade(label='Run Module')
57submenu4.add_command(label='Check Module')
58
59submenu5=Menu(menu1)
60menu1.add_cascade(label='Options',menu=submenu5)
61submenu5.add_command(label='Configure IDLE')
62submenu5.add_cascade(label='Show Code Context')
63submenu5.add_command(label='Zoom Height')
64
65submenu6=Menu(menu1)
66menu1.add_cascade(label='Window',menu=submenu6)
67submenu6.add_command(label='Python 3.7.3 shell')
68submenu6.add_cascade(label='Untitled')
69submenu6.add_command(label='Resize window',command=Res)
70submenu6.add_command(label='Norml size window',command=B2N)
71submenu6.add_command(label='Large window',command=Full)
72
73submenu7=Menu(menu1)
74menu1.add_cascade(label='Help',menu=submenu7)
75submenu7.add_command(label='About IDLE')
76submenu7.add_cascade(label='IDLE Help')
77submenu7.add_command(label='FAQ')
78submenu7.add_command(label='Contact US')
79
80
Mohamed-Ali
10 Oct 2016
1from tkinter import *
2
3def do_some():
4    print('Do some!')
5
6root = Tk()
7
8main_menu = Menu(root)
9root.config(menu=main_menu)
10
11
12# Type 1 Menu
13main_menu.add_command(label='File', command=do_some)
14# Type 1 Menu
15
16
17# Type 2 Menu
18file_menu = Menu(main_menu)
19main_menu.add_cascade(label='File', menu=file_menu)
20
21file_menu.add_command(label='Save', command=do_some)
22file_menu.add_command(label='Save As', command=do_some)
23# Type 2 Menu
24
25
26# Type 3 Menu
27file_menu = Menu(main_menu)
28main_menu.add_cascade(label='File', menu=file_menu)
29
30save_menu = Menu(file_menu)
31save_as_menu = Menu(file_menu)
32
33file_menu.add_cascade(label='Save', menu=save_menu)
34file_menu.add_cascade(label='Save As', menu=save_as_menu)
35
36save_menu.add_command(label='New', command=do_some)
37save_menu.add_command(label='Old', command=do_some)
38save_as_menu.add_command(label='New', command=do_some)
39save_as_menu.add_command(label='Old', command=do_some)
40# Type 3 Menu
41
42root.mainloop()
Brydon
09 May 2017
1# python console helpMenu // OptionMenu
2# Easy to read
3
4menu_options = {
5    1: 'Name your option here' ,
6    2: 'Name your option here' ,
7    3: 'Name your option here' ,
8    4: 'Exit' ,
9}
10print('\n')
11def print_menu():
12
13    for key in menu_options.keys():
14        print(key , '--' , menu_options [key] )
15
16def option1():
17    print('Option description Here')
18
19def option2():
20     print('Option description Here')
21    
22
23def option3():
24     print('Option description Here')
25    
26
27if __name__ == '__main__':
28
29    while(True):
30
31        print_menu()
32        
33        option = ""
34        
35        try:
36            
37            option = int(input('Enter Your Chouce: '))
38        
39        except:
40
41            print('Selected:' , option)
42            
43        if option == 1:
44            option1()
45
46           #
47           # Code here
48           #   
49
50        elif option == 2:
51            option2()
52
53            #
54            # Code here
55            #            
56
57        elif option == 3:
58            option3()
59        
60            # Code here
61            #
62            #
63
64        elif option == 4:
65            print('Exit the program...')
66
67            exit()
68
69        else:
70            print('\n')
71            print('Error Message Here')
72
Valeria
28 Aug 2019
1from tkinter import (
2    Tk,
3    Label,
4    Menu,
5    messagebox,
6)
7
8
9# some example functions
10def Res():
11    root.geometry("333x222")
12
13
14def B2N():
15    root.geometry("444x444")
16
17
18def Full():
19    root.geometry("1000x700")
20
21
22def custom_quit():
23    answer = messagebox.askokcancel(
24        "Are you Sure?", "Your Data will be lost if you exit"
25    )
26    if answer:
27        quit()
28
29
30# the main window
31root = Tk()
32root.geometry("444x444")
33text = Label(root, text="*my first menu*").pack()
34# the actual menu (used a big example for better understanding of menu and sub-menu)
35menu1 = Menu(root)
36root.configure(menu=menu1)
37
38submenu1 = Menu(menu1)
39menu1.add_cascade(label="File", menu=submenu1)
40sub2menu = Menu(submenu1)
41sub2menu.add_command(label="Recent")
42sub2menu.add_command(label="Browse")
43
44submenu1.add_command(label="New File")
45submenu1.add_cascade(label="Open File", menu=sub2menu)
46submenu1.add_command(label="Save As")
47submenu1.add_command(label="Print")
48submenu1.add_command(
49    label="Quit", command=custom_quit
50)  # adding command to menu elements
51
52submenu2 = Menu(menu1)
53menu1.add_cascade(label="Edit", menu=submenu2)
54submenu2.add_command(label="Undo")
55submenu2.add_cascade(label="Redo")
56submenu2.add_command(label="Cut")
57submenu2.add_command(label="Copy")
58submenu2.add_command(label="Paste")
59submenu2.add_command(label="Select All")
60
61submenu3 = Menu(menu1)
62menu1.add_cascade(label="Format", menu=submenu3)
63submenu3.add_command(label="Indent Region")
64submenu3.add_cascade(label="Comment")
65submenu3.add_command(label="All")
66submenu3.add_command(label="Selected")
67submenu3.add_command(label="Format Paragraph")
68
69submenu4 = Menu(menu1)
70menu1.add_cascade(label="Run", menu=submenu4)
71submenu4.add_command(label="Python Shell")
72submenu4.add_cascade(label="Run Module")
73submenu4.add_command(label="Check Module")
74
75submenu5 = Menu(menu1)
76menu1.add_cascade(label="Options", menu=submenu5)
77submenu5.add_command(label="Configure IDLE")
78submenu5.add_cascade(label="Show Code Context")
79submenu5.add_command(label="Zoom Height")
80
81submenu6 = Menu(menu1)
82menu1.add_cascade(label="Window", menu=submenu6)
83submenu6.add_command(label="Python 3.7.3 shell")
84submenu6.add_cascade(label="Untitled")
85submenu6.add_command(label="Resize window", command=Res)
86submenu6.add_command(label="Norml size window", command=B2N)
87submenu6.add_command(label="Large window", command=Full)
88
89submenu7 = Menu(menu1)
90menu1.add_cascade(label="Help", menu=submenu7)
91submenu7.add_command(label="About IDLE")
92submenu7.add_cascade(label="IDLE Help")
93submenu7.add_command(label="FAQ")
94submenu7.add_command(label="Contact US")
95
96root.mainloop()
97
queries leading to this page
python tkinter menu optionswindow menu tkintercreating a menu in pythonhow to add a menu in tkinterhow to make a menu in pythonmake a menu tkintermenu in tnkintermenu tkinter settingpython creating a menupython how to make a menutkinter menu examplehow to create a menu in pythonpython library to create menutkinter menu itemmenu by tkinteraccess tkinter menu objecthow add a menu for tkinterpython tkinter about menumenu 28computing 29 tkinter widgetshow to create menubars in tkinterhow to createa a menu gui using tkintertkinker menutkinter menu add command methodspython gui tkinter menu examplwhow to make menubar in pythonhow catrey a mune in tk intercommand for menu tkintertkinter menustkinter menu widgettkinter python menue listadding menus tkintertkinter menu bar menubar in tkintermenu item python tkintermenu widget in tkinter pythonadd menubar tkinterhow to make a label as menu in tkinterpython menu examplecascade tkinter pythontkinter menubarmenubar tkinter documentationhow to set custom menus in tkintertkinter where to add menumenu button in tkinter pythonhow to create menu in tkinter pythontkinter create a menucreate a menu in python tkinterentry in the menu in tkintertkinter menu bar pythonhow to add menu bar buttons in tkinterlist menu tkintercreate a menu tkintermenu command tkinter pythonhow to create a menu in python 3menu creation in pythonmenu in pytho ntpython tkinter button menumenu pytkinter menu 28menu program in pythoncreating a menu in tkintermenu designs tkinytertkinter example menupython create menuadd command to menu tkintermaking a menu in pythontkinter advanced menupython menu simpletkinter add menu barpython create menustkinter menu methodsmenu tkinterhow to write menu in pythonmenu button tkintermenu pythonhow to create menu tkintermenu bar pythonset menu tkintertkinter python build menutkinter menu button functiontkinter cascadeadd command in menu of tkintermenubar tkinter c3 b9menu in tkinterwhat is menu in tkinterhow to do menus in pythontkinter menu button commandmenu bar tkinter pythonpython tkinter main menutkinter menu tutorialadd a menu to window tkintertkinter menu windowscreating a menu bar in tkintertkinter update menutkinter menu configmenu tkinter exampletkinter menus examplehow to add menu bar in tkintertoplevel tkinter with menupython tkinter add commandsimple menu in python when toggling between menu buttons they duplicate tkinitercreating menu in tkinterhow to make a menu bar in tkintertkinter window menuhow to make different menus in tkintertkinter menuhow to add menu in tkintermenus tkintermenu in python tkintermake a menu with tkinter in pythontkinter menu add command optionstkinter gui menuadd command pythontkinter menu systemconfigure menut command tkintermenu widget in tkinteradd menu in tkinteradd menu items in pythontkinter window menu baradd menu tkinterbest way to implement a menu in pythontkinter tutorial menumenu widget tkintertkinter menuoptiontkinter menu button pythonmenubar tkintereasiest way to make a menu in pythontkinter python menu barhow to make menu pythontkinter menu add commandpython how to create a menutkinter menupython menupython menu exampleshow to add new menu in tkintermaking a menu in tkinterpython tkinter menu widgetcreating a menu for python creating menu in pythontkinter menu addset item menu tkinterpython tkinter menumenu based program in pythoncreate menu bar in tkinterhow to use menu tkinterpython menu programmenubar command tkintercreating menu with tkinterwhat is activate 28 29 in tkinter menutk menu add cascadepython simple menu codehow to make a menu bar in python topadd a menu bar tkintertkinter menu system example python 3menu widgets for pythonpython gui tkinter menumenu in pythontkinter make menutinkter add comman 28command 3dmenus in tkinterhow to display a menu in tkinterhow to create menu in tkintersimple python menufilemenu tkintertkinter menu helphow to add menu bars in tkintermenuba fo the toplevel tkinteradding menu in tkintercascade in tkintercreate a menu python tkintermake menu in pythonadd menubar to window tkintermaking a menu in python with tkintermake amenu python guifiel menu in tkintermenu in tkinter python 3tkinter top menuadd menus to tkinterhow to create a menu in tkinterpython menu command codehow to create menu in python tkinterhow to create menus tkintercascade in tkinter meaningtkinter menu add command optionscustom menubar tkintermenu in toplevel tkinterbuilt in menu in pythonhow to create menu in pythonmenu bar tkintermenu in a function pythonsimple menu pythontkinter cascade menutkinter menu 5chow to make menu in tkintermenu bar in tkinterhow to make a menu in tkintertoplevel tkinter with menu tkintermenu tutorial in tkinterhow to show a menu in pythonmenu lisg in tkintertkinter menu coomand that opens menubuld menu in pythoncreate menu in pythonhow to create menu bar window in tkinteruse of tearoff in tkinter pythonmenu tkinter pythoncustom menu tkintertkinter where to add menubarmenu function tkintermake a menu in pythonadd buttons to a tkinter menu barmenu in menu tkinterpython full menu with tkintercreating a menu tkinterpython show menucreate menu with option in tkintercreate menu python tkinter 2amenu tkinter pytohnpython3 menumaking a menu in python functionstkinter menu optionspython menu systempython tkinter menu barpython menu in classwidgets for python menumenu 27s pythontkinter menubar examplemenu creation from pythonpython tkinter menu invokepython tkinter menu buttontkinter menu documentationtkinter create menuhow to add menubar in tkintercreate a menu with pythonmenu python tkintercreate menu with option bar in tkintertkinter ajouter menutkinter menu buttonmenu in python