[Tkinter-discuss] [Tutor] Tix: binding

Adam adam.jtm30 at gmail.com
Wed Mar 15 18:36:24 CET 2006


On 15/03/06, hk at pop.ms <hk at pop.ms> wrote:
> I am looking at Tix and I am stuck with what seems to be a simple problem:
>
> I want to bind the cancel buttom of a ExFileSelectBox to a routine in my class, but can not make it work.
> I guess the problem is the same for any binding of tix sub-widgets, so if someone could send some sample code.
> >>> import Tix
> >>> root = Tix.Tk()
> >>> box = Tix.ExFileSelectBox(root)
> >>> print box.subwidget(name='cancel')
> .11827520.bf.cancel                            #so the sub-widget cancel buttom is there
>
> But how to bind it ?
>
> >>> box.cancel(command = lambda a,b : a+b )
> Traceback (most recent call last):
>   File "<pyshell#12>", line 1, in ?
>     box.cancel(command = lambda a,b : a+b )
> AttributeError: _dummyButton instance has no __call__ method
>
> Or
>
> >>> box.subwidget(name='cancel' , command = lambda a,b : a+b )
> Traceback (most recent call last):
>   File "<pyshell#13>", line 1, in ?
>     box.subwidget(name='cancel' , command = lambda a,b : a+b )
> TypeError: subwidget() got an unexpected keyword argument 'command'
>
> So, it seems I can not bind to command, but what then ?
> >From the Tix docu I thought the buttoms are normal Tkinter widgets ?
> --
> Harm

Here's what I got from a little experimentation and print
box.cancel.bind.__doc__.

>>> def bar(action):
...     print action
>>> import Tix
>>> root = Tix.Tk()
>>> box = Tix.ExFileSelectBox(root)
>>> box.pack()
>>> box.cancel.bind("<ButtonPress-1>", bar)
'-1212073588bar'
>>> <Tkinter.Event instance at 0xb779c0ec>
<Tkinter.Event instance at 0xb779c0ec>
<Tkinter.Event instance at 0xb779c0ec>

If you have a look at box.cancel.bind.__doc__ you can find everything
you can put into the SEQUENCE string "<ButtonPress-1>" is left mouse
click.


More information about the Tkinter-discuss mailing list