how to create a submenu in python? how to use insert_cascade(index,**options)..........

please help me out.

Recommended Answers

All 2 Replies

This would be example from one of the tutorials:

# Tkinter top-level menus

from Tkinter import *
from tkMessageBox import *

# temporary function to call from menu
def notdone():
    showerror('Not yet', 'Work in progress!')

def makemenu(win):
    top = Menu(win)
    file = Menu(top)
    file.add_command(label='New...', command=notdone, underline=0)
    file.add_command(label='Open...',command=notdone, underline=0)
    file.add_command(label='Quit', command=win.quit, underline=0)
    top.add_cascade(label='File', menu=file, underline=0)

    edit = Menu(top, tearoff=0)
    edit.add_command(label='Cut', command=notdone, underline=0)
    edit.add_command(label='Paste', command=notdone, underline=0)
    top.add_cascade(label='Edit', menu=edit, underline=0)

    submenu = Menu(edit, tearoff=0)
    submenu.add_command(label='Spam', command=win.quit, underline=0)
    submenu.add_command(label='Eggs', command=notdone, underline=0)
    edit.add_cascade(label='Stuff', menu=submenu, underline=0)

root = Tk()
msg = Label(root, text='Window menu basics')
msg.pack(expand=YES, fill=BOTH)
msg.config(relief=SUNKEN, width=40, height=7, bg='beige')

hi i was wandering if you wanted to keep track of where someone clicked in the menu how would you go about doing that?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.