Sunday, March 25, 2007


OK, so I'm trying to create a dropdown menu with around 40 options using the Python lib Tkinter. I've just learned that you can't just define a command - call it get - and pass in the option as a variable (i.e. def get(variable) and then, for option X, command=get(X)), which brings me the horrible prospect of defining 40 or so functions that would only be different in that they have a different string variable.

This is obviously a stupid way to do it, and one that involves a lot of mindless copying. I'm thinking either: create a list and assign a number to each option, then callback the numbers, or else: do a for..while loop that would create the 40 or so functions when the class is instantiated. I'm not sure how to catch the callback in the first, or whether you're allowed to autogenerate functions.

Thoughts? (The wanker is me, btw.)

1 comment:

Anonymous said...

Alex, my Python is rusty, but perhaps I can point you in a useful direction.

It's probably easiest for you to use "lambda" to generate your callback function, but there are more general methods of handling similar problems.

Hope this helps.

kostenloser Counter