Bleggin’

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. Anonymous

    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.




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s



%d bloggers like this: