[Tutor] Tix: binding

John Fouhy john at fouhy.net
Wed Mar 15 23:24:56 CET 2006

On 16/03/06, Adam <adam.jtm30 at gmail.com> wrote:
> On 15/03/06, hk at pop.ms <hk at pop.ms> 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("<ButtonPress-1>", bar)
> '-1212073588bar'
> >>> <Tkinter.Event instance at 0xb779c0ec>
> <Tkinter.Event instance at 0xb779c0ec>
> <Tkinter.Event instance at 0xb779c0ec>

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= ...).


More information about the Tutor mailing list