The same code as my previous post, but because of this list thing, i'm not able to run specific commands for different options. Here i have 2 options under the 'Names' Menu, 'rajat','prasun', now when the user selects either of them i should be able to know which one he selected and run the command associated for it. i've tried some stuff like trying to use 'variable' or 'value' properties but its just not working.. any hints would be helpful..

from Tkinter import *

fileObj = open("c:/test","w")

file1 = open("c:/test","r")
lines = file1.readlines()

root = Tk()
menubar = Menu(root)
filemenu = Menu(menubar)

for line in lines:


A Google for "Tkinter menu" will yield numerous examples. New Mexico Tech http://infohost.nmt.edu/tcc/help/pubs/tkinter/
and Fredrik Lundh http://hem1.passagen.se/eff/
have good Tkinter sites. The following code came from "Charming Python", also a good site. http://www.ibm.com/developerworks/linux/library/l-tkprg/#h5

def help_menu():
    help_btn = Tkinter.Menubutton(menu_frame, text='Help', underline=0)
    help_btn.pack(side=Tkinter.LEFT, padx="2m")
    help_btn.menu = Tkinter.Menu(help_btn)
    help_btn.menu.add_command(label="How To", underline=0, command=HowTo)
    help_btn.menu.add_command(label="About", underline=0, command=About)
    help_btn['menu'] = help_btn.menu
    return help_btn

I havn't checked the links yet but this example is not what i want, Here we are calling a separate command for each menu option, however i have to be able to call the same command for each Menu option but in the function i should be able to find out that from which Menu Option the call has come so that i can do some specific work then. Basically for each Menu Option i will have a file of the same menu name in some locaion. So if i can make out the 'label' property in the function i can simply replace the file name with the 'label' name and thus using just one fn i can accomplish this. i need this because the menu options are extensible also, so i cant dynamically keep adding more fns for new menu's. hence i need to fire just one command for each option

Ok so i found that out ... we need use the 'variable' and 'value' properties of the radiobutton

something like:


now when the user clicks on any menu i can check for the 'variable' value. self.v is a string

print self.v.get()

This gives me the 'value' property and i can identify which option was selected.

Keeping this still open, incase someone has a better way of doing it..