ANN: Thinking in Tkinter

Steve Holden sholden at holdenweb.com
Fri Sep 13 13:43:31 CEST 2002


"GerritM" <gmuller at worldonline.nl> wrote ...
> "Russell E. Owen" <owen at nospam.invalid> schreef ...
> <...snip...>
> > True. It would help if the command callback sent an arguement that
> > identified the widget (making it look a bit more like an event binding).
> > In any event, it doesn't and command is unfortunately still the best way
> > to handle button widgets.
>
> In a recent thread it was pointed out that you can also bind to s function
> of a specific object instance. Out of the top of my head:
>
> Class A:
>     def printarg( self, arg ):
>         print arg
>
> anA = a()
> functionBoundToInstance = anA.printarg
>
> functionBoundToInstance("Hello Python")
>
> Hello Python
>
> this would work also for widgets, command = aWidget.activate
>
It also works for widget subclasses, which means that you have "self"
available to access various attributes of the widget. But it still doesn't
get you the event data, which only get explicitly passed when you establish
a binding for an event rather than using the command argument.

regards
-----------------------------------------------------------------------
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/
Previous .sig file retired to                    www.homeforoldsigs.com
-----------------------------------------------------------------------






More information about the Python-list mailing list