Thanks John,

if I have to bind in all children the "check" function, when I would
find it simpler to bind the dragStart directly

Vasiis

________________________________________
From: johnmc [joh...@velseis.com]
Sent: Thursday, September 08, 2016 12:21
To: Vasilis Vlachoudis; tkinter-discuss@python.org
Subject: Re: [Tkinter-discuss] Frame button binding

On Tue, 6 Sep 2016 09:00:45 +0000, Vasilis Vlachoudis wrote
> Hi all,
>
> I want to create a Scrolled Frame, it works nicely with the place command
> however when I bind the B2-Motion, and I click the middle mouse button
> on the child buttons instead of dragging it does nothing, since they are
> capturing the B2 and not propagate it to the master.
>
> SimplifiedExample:
>
> def dragStart(e):
>     print "B2-pressed")
>
> f = Frame(tk)
> f.pack(expand=YES, fill=BOTH)
> f.bind("<Button-2>", dragStart)
>
> Button(f, text="Button").pack()
>
> I found a not elegant solution of setting the bind to the toplevel like
> f.winfo_toplevel().bind("<Button-2>", dragStart)
>
> and in dragStart I am checking
>      if not str(e.widget).startswith(str(f)): return
>
> Is there a better way of doing it?
>


Hi Vasilis,

I'm a bit late in this discussion, but have you tried the following (a 
modification
of your simplified code):

from Tkinter import *

root = Tk()

def dragStart(e):
    print "B2-pressed"

def check(e):
    print "Button pressed with B2"
    return "break"

f = Frame(root)
f.pack(fill=BOTH, expand=YES)
root.bind("<Button-2>", dragStart)

b = Button(f, text='Button')
b.pack()
b.bind("<Button-2>", check)

root.mainloop()


In the above the <Button-2> event is bound to all the widgets in the Toplevel. 
There
is also a separate binding specific to the Button widget.  If the <Button-2> 
event
happens on the Button "b" widget it is not propagated to the higher binding 
level by
means of the "break" return.

Regards,

John


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to