python menu

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

showing results for - "python menu"
Graeme
17 Feb 2020
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
Célestin
18 Jan 2020
1# python console helpMenu // OptionMenu
2# Updated 2021 Oct 18 18:14
3# Your Option Menu you can add more option for your needs.
4# TODO Option Menu Below rename it to what the function will do.
5# Example: your function will download something,
6# Then you rename Option 1 To Download Something,
7
8option_menu = {
9	1: 'Option 1' , 
10	2: 'Option 2',
11	3: 'Exit' ,
12}
13
14# This function will print out your option menu
15def print_options():
16	
17	for key in option_menu.keys():
18		print(key , '---' , option_menu[key])
19
20# Create your option functions here. / Add more for your needs
21def option1():
22	pass
23
24
25def option2():
26	pass
27
28
29
30if __name__ == '__main__':
31	
32	while(True):
33
34		print_options()
35
36		option = ""
37
38		try:
39			# Edit 'Enter option' for your need.
40			option = int(input('Enter option:'))
41
42		except:
43
44			print('option' , option)
45
46		if option == 1:
47			option1()
48			#
49			# Code here
50			#
51			# Also change the print massage. for your need
52			print("OPTION1 WORKING....")
53
54		elif option == 2:
55			option2()
56			#
57			# Code here
58			#
59			# Also change the print massage. for your need
60			print("OPTION2 WORING....")
61
62		elif option == 3:
63			# Set your Exit message here. for your need
64			print("Exit code....")
65			exit()
66
67			# Set Your Error masage Here for your Need.
68		else:
69			print('invalid option:' , option ,'Try again...')
queries leading to this page
how to create a menu in pythonpython create menusbest way to implement a menu in pythonmenu based program in pythonsimple menu pythoncreate menu pythonpython3 menupython create menucreating a menu in pythonpython how to create a menu to run functionsmenu creation in pythonsimple menu in python how to create a menu in python 3python menu systemmake a menu in pythoneasiest way to make a menu in pythonmenu in python with classcreating menu in pythonhow to show a menu in pythonhow to create a menu pythonpython simple menu codemenu in python 3how to do menus in pythonbuld menu in pythonmenu in pytho npython menu command codemaking a menu in python functionssimple python menupython creating a menumenu 27s pythonhow to create menu in pythonpython library to create menubuilt in menu in pythoncode menu pythonpython menu examplescreating a menu for python how to write menu in pythonmenu in pythonhow to make menu pythonmenu program in pythonpython create menu from listmaking a menu in pythoncreate a menu with pythonpython menu tuipython show menupython menu simplemake menu in pythonhow to make menu with list in pythonmenu system pythonmenu code in pythonmenus in pythonpython how to create a menuhow to use menus in pythonpython create a menumenu creation from pythonpython make menupython menu code simplepython menu in classpython menu example code simplepython menu examplemenu in a function pythonpython simple menu python menue code simplemenu pythonpython menu layoutsource code to make menu in pythonpython how to make a menucreate a menu with python cmdpython simple menusmenu class pythonhow to make a menu in pythonpython menucreate menu in pythonpython menu programmenu bar pythonpython menu librarymenu pyhow to do cool menu in pythonpython menu