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 Comment on "Bleggin’"

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.