Two naive Tkinter questions
alan.gauld at btinternet.com
Mon Nov 3 09:15:28 CET 2003
On Sun, 02 Nov 2003 21:32:12 GMT, "Andrew Koenig" <ark at acm.org>
> Your first suggestion, knowing that setcolor deals with self.b1, doesn't
> work with my application because I'm going to have lots of these buttons,
> and I want to be able to set their colors independently.
A slight variant on the technique using lambda is:
self.b1 = Button(self, bg = "red",
Here we use the lambda to call the setcolor method with
the widget parameter and use that within the setcolor method.
This way you keep one method but call it from several places.
The downside is you introduce an extra function call, but in
a GUI event handler that's not going to be a problem!
Author of the Learn to Program website
More information about the Python-list