Menu Demo 1

This is a very simple example of creating a menu. (Note that the open file command is just for show and just prints something to your console.)  The point here is to show creating a couple of primary menus which will create a menu bar and then using the add_cascade command to make a place for adding some command options underneath a menu.

<pre>#TEST AREA forcommands/methods/options/attributes
#standard set up header code 2 
from tkinter import *
root = Tk()
root.attributes('-fullscreen', True)
root.configure(background='SteelBlue4')
scrW = root.winfo_screenwidth()
scrH = root.winfo_screenheight()  
workwindow = str(1024) + "x" + str(768)+ "+" +str(int((scrW-1024)/2)) + "+" +str(int((scrH-768)/2))
top1 = Toplevel(root, bg="light blue")
top1.geometry(workwindow)
top1.title("Top 1 - Workwindow")
top1.attributes("-topmost", 1)  # make sure top1 is on top to start
root.update()                   # but don't leave it locked in place
top1.attributes("-topmost", 0)  # in case you use lower or lift
#exit button - note: uses grid
b3=Button(root, text="Egress", relief=RAISED, command=root.destroy)
b3.grid(row=0,column=0,ipadx=10, ipady=10, pady=5, padx=5, sticky = W+N)
#____________________________
from tkinter.filedialog import askopenfilename

def NewFile():
    print ("New File!")
def OpenFile():
    name = askopenfilename()
    print (name)
def About():
    print ("This is a simple example of a menu")
    
menu = Menu(top1, bd=30)
top1.config(menu=menu)
filemenu = Menu(menu)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="New", command=NewFile)
filemenu.add_command(label="Open...", command=OpenFile)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)

helpmenu = Menu(menu)
menu.add_cascade(label="Help", menu=helpmenu)
helpmenu.add_command(label="About...", command=About)

introText="The purpose of this script is to demo the menu above (no MenuButton widget)"
l1=Label(top1, text= introText)
l1.pack(padx=200, pady=200, ipadx=10, ipady=10)

#____________________________
root.mainloop()
#root.fileName = filedialog.askopenfilename (filetypes = (("howcode files", "*.hc"), (All files", "*.*)))</pre>

]