More Tkinter menu problems

kiki kiki at pixar.com
Wed Jun 2 20:06:44 EDT 1999


Here's a new problem which is much like my old problem with a new
twist...

I'm making a color menu class now.  In the menu is mainly "Add Color"
and the current list of colors.  When you choose "Add Color", the user
makes a color, then names it.  From here, I want to append the color to
the menu, in much the same way I appended my mondo_menu call -- again, I
have a group of menu items which are all the same action on slightly
different data.

I tried the suggested lambda idea:

  self.menu.add_command(label = new_name,
   command = lambda temp_color = new_color:
   self.select_color(temp_color))

but I get a Name Error on "self".  So now "self" is out of scope when
the menu call happens.

Is there *really* no better way to have a single function handle a group
of similar menu items?  Not only would that be useful, but in many cases
like these it's *necessary*.  I still think it would sure be nice to get
an event record back from *all* events, including menu events... :(

Thanx!

Kiki

PS Greg McFarlane: you are absolutely right in scolding me for my
over-use of eval. I've never used it nor had a need for such a thing
before, but now I'm getting interpreter-giddy. :) Learning those "safer"
and more lovely methods is what I'm-a trying to do. :) Speaking of, is
there a way to take the *string* "Kikis_modules.Fractal" and turn it
into "Fractal" gracefully without doing eval(class_name).__name__?  I
tried "import Perl" but that didn't work. ;) hee-hee





More information about the Python-list mailing list