Re: [Tutor] Tix: binding

2006-03-15 Thread John Fouhy
On 16/03/06, Adam <[EMAIL PROTECTED]> wrote:
> On 15/03/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > I want to bind the cancel buttom of a ExFileSelectBox to a routine in my 
> > class,
> 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("", bar)
> '-1212073588bar'
> >>> 
> 
> 

This will bind to leftmouse-down, which is different from clicking a
button.  If you want to simulate a real button click with event
bindings, you will need to set a flag on ButtonPress-1, then in
ButtonRelease-1 check for the flag, check to see if the mouse is
within the button, and then activate your callback.

Something else you could try (which I haven't tested) --- instead of
box.cancel.bind, do box.cancel.config(command= ...).

--
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tix: binding

2006-03-15 Thread Adam
On 15/03/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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 "", 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 "", 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("", bar)
'-1212073588bar'
>>> 



If you have a look at box.cancel.bind.__doc__ you can find everything
you can put into the SEQUENCE string "" is left mouse
click.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Tix: binding

2006-03-14 Thread hk
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 "", 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 "", 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 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor