[tkinter] Event from menu event?

Greg McFarlane gregm at iname.com
Tue May 25 20:45:21 EDT 1999


Please, please, do not use eval or exec unless in an emergency (or
when testing/debugging).  There almost always cleaner (and safer) ways
of doing what you want.  For example:

    def myfunc(label):
	print label

    for each_class in draw_class_name:
	mymenu.add_command(
	    label = each_class,
	    command = lambda e = each_class: myfunc(e)
	)

On 25 May, kiki wrote:
> Aha!!  Figured it out!!
> 
> 
>   menu_call = "lambda: mondo_menu_call('%s')"% stitch_name
> 
>   pattern_data.haiku_menu.add_haiku_item(
>    eval(stitch_name).__name__,
>    eval(menu_call))
> 
> That did it!
> 
> Thanx for all your help.  I wouldn't've figured it out without it!
> 
> Kiki -- now I guess I should actually get some work done instead of play w/ my
> program... :-)
> 
> 
> 

-- 
Greg McFarlane:    INMS Telstra Australia (gregm at iname.com)
Today's forecast:  Sunny, with occasional cloudy periods and a chance
		   of rain in some areas.




More information about the Python-list mailing list