Sunday, August 3, 2008

Creating a ButtonChooser with a list of keys

Because the ButtonChooser takes in a separate argument for each key, it's not obvious how to feed it a list. The trick is to make use of a handy bit of python syntax (see 7/8 of the way down for info on the *arguments kind of optional arguments).

For instance:

keys = ['A', 'B', 'C']
bc = ButtonChooser(*[Key(key) for key in keys])

No comments: