Re: [Tkinter-discuss] Frame button binding
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 +, 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("", dragStart) > > Button(f, text="Button").pack() > > I found a not elegant solution of setting the bind to the toplevel like > f.winfo_toplevel().bind("", 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("", dragStart) b = Button(f, text='Button') b.pack() b.bind("", check) root.mainloop() In the above the event is bound to all the widgets in the Toplevel. There is also a separate binding specific to the Button widget. If the 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
Re: [Tkinter-discuss] Frame button binding
BTW is there a method to get back from Tkinter which function is binded for a message? From: Tkinter-discuss [tkinter-discuss-bounces+vasilis.vlachoudis=cern...@python.org] on behalf of Michael Lange [klappn...@web.de] Sent: Wednesday, September 07, 2016 22:47 To: tkinter-discuss@python.org Subject: Re: [Tkinter-discuss] Frame button binding Hi, On Wed, 7 Sep 2016 14:01:19 + Vasilis Vlachoudis <vasilis.vlachou...@cern.ch> wrote: > Until now I had the scrollbar working which is not very elegant vs the > Mouse Wheel or middle mouse drag. Everything started in a new > application I was doing for RPi as a home server that uses full screen > with no scrollbar and acts on gestures. But I wanted it general so that > my other programs could benefit of it. > > What if I bind the toplevel on a static method of the ScrollFrame only > once by keeping a list of registered scrollframes, and then I check if > the hit location is inside any of the ScrollFrames. > > Is there any fast method to see if a point event.x_root, y_root is > inside a widget or do I have to make the comparison with the winfo_xxx > () information Shouldn't simply using event.widget in the callback be the easiest way to check which frame (resp. child widget) was clicked? Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Blast medicine anyway! We've learned to tie into every organ in the human body but one. The brain! The brain is what life is all about. -- McCoy, "The Menagerie", stardate 3012.4 ___ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss ___ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss
Re: [Tkinter-discuss] Frame button binding
On Tue, 6 Sep 2016 09:00:45 +, 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("", dragStart) > > Button(f, text="Button").pack() > > I found a not elegant solution of setting the bind to the toplevel like > f.winfo_toplevel().bind("", 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("", dragStart) b = Button(f, text='Button') b.pack() b.bind("", check) root.mainloop() In the above the event is bound to all the widgets in the Toplevel. There is also a separate binding specific to the Button widget. If the 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
Re: [Tkinter-discuss] Frame button binding
Hi Michael, the ScrollFrame is of generic use as a normal frame class. So I don't know apriori how many children it will have. I could set the bind recursively in all winfo_children() and sub-children etc. after the frame is populated but I though it will be an overkill. Vasilis From: Tkinter-discuss [tkinter-discuss-bounces+vasilis.vlachoudis=cern...@python.org] on behalf of Michael Lange [klappn...@web.de] Sent: Tuesday, September 06, 2016 23:24 To: tkinter-discuss@python.org Subject: Re: [Tkinter-discuss] Frame button binding Hi, On Tue, 6 Sep 2016 09:00:45 + Vasilis Vlachoudis <vasilis.vlachou...@cern.ch> 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. (...) Have you tried to simply add a binding for the event to the Frame's children, as in b = Button(f, text="Button") b.pack() b.bind("", dragStart) ? Best regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. No more blah, blah, blah! -- Kirk, "Miri", stardate 2713.6 ___ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss ___ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss
Re: [Tkinter-discuss] Frame button binding
Hi, On Wed, 7 Sep 2016 14:01:19 + Vasilis Vlachoudiswrote: > Until now I had the scrollbar working which is not very elegant vs the > Mouse Wheel or middle mouse drag. Everything started in a new > application I was doing for RPi as a home server that uses full screen > with no scrollbar and acts on gestures. But I wanted it general so that > my other programs could benefit of it. > > What if I bind the toplevel on a static method of the ScrollFrame only > once by keeping a list of registered scrollframes, and then I check if > the hit location is inside any of the ScrollFrames. > > Is there any fast method to see if a point event.x_root, y_root is > inside a widget or do I have to make the comparison with the winfo_xxx > () information Shouldn't simply using event.widget in the callback be the easiest way to check which frame (resp. child widget) was clicked? Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Blast medicine anyway! We've learned to tie into every organ in the human body but one. The brain! The brain is what life is all about. -- McCoy, "The Menagerie", stardate 3012.4 ___ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss
Re: [Tkinter-discuss] Frame button binding
Until now I had the scrollbar working which is not very elegant vs the Mouse Wheel or middle mouse drag. Everything started in a new application I was doing for RPi as a home server that uses full screen with no scrollbar and acts on gestures. But I wanted it general so that my other programs could benefit of it. What if I bind the toplevel on a static method of the ScrollFrame only once by keeping a list of registered scrollframes, and then I check if the hit location is inside any of the ScrollFrames. Is there any fast method to see if a point event.x_root, y_root is inside a widget or do I have to make the comparison with the winfo_xxx() information Thanks Vasilis From: Tkinter-discuss [tkinter-discuss-bounces+vasilis.vlachoudis=cern...@python.org] on behalf of Michael Lange [klappn...@web.de] Sent: Wednesday, September 07, 2016 12:31 To: tkinter-discuss@python.org Subject: Re: [Tkinter-discuss] Frame button binding Hi, On Wed, 7 Sep 2016 10:21:02 + Vasilis Vlachoudis <vasilis.vlachou...@cern.ch> wrote: > Thanks for the idea. It will make the code indeed odd. > I was looking for a less intrusive method, something that I could > easily replace the Frame() with ScrollFrame() in an existing application > and everything should work. I had the same problem quite a while ago; finally I decided that if I want to scroll the frame I will just need to use the scrollbar ;) I don't remember what exactly I tried back then, at least I can say if there's an easy solution, then I did not find it. > > My approach with binding on the toplevel works only if I have only one > ScrollFrame, but if I have more in the application then it doesn't. Exactly, and possibly nested ScrolledFrames make it even worse. > What happens if I bind more than once a certain event? Does Tk calls in > chain all handlers or only the last one? By default, with add=False , only the last binding should be active. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Women are more easily and more deeply terrified ... generating more sheer horror than the male of the species. -- Spock, "Wolf in the Fold", stardate 3615.4 ___ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss ___ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss
Re: [Tkinter-discuss] Frame button binding
Thanks for the idea. It will make the code indeed odd. I was looking for a less intrusive method, something that I could easily replace the Frame() with ScrollFrame() in an existing application and everything should work. My approach with binding on the toplevel works only if I have only one ScrollFrame, but if I have more in the application then it doesn't. What happens if I bind more than once a certain event? Does Tk calls in chain all handlers or only the last one? Vasilis From: Tkinter-discuss [tkinter-discuss-bounces+vasilis.vlachoudis=cern...@python.org] on behalf of Michael Lange [klappn...@web.de] Sent: Wednesday, September 07, 2016 11:53 To: tkinter-discuss@python.org Subject: Re: [Tkinter-discuss] Frame button binding Hi, On Wed, 7 Sep 2016 06:31:06 + Vasilis Vlachoudis <vasilis.vlachou...@cern.ch> wrote: > Hi Michael, > > the ScrollFrame is of generic use as a normal frame class. So I don't > know apriori how many children it will have. I could set the bind > recursively in all winfo_children() and sub-children etc. after the > frame is populated but I though it will be an overkill. > I see your point of course, especially since probably other events than should be handled, too. Not sure if there is an easy solution to this, though. One possibility that comes to mind is adding custom geometry methods to the ScrolledFrame class that handle the bindings, like: def pack_child(self, child, **kw): child.pack(**kw) child.bind("", self.dragStart) Then you could conveniently do something like b = Button(f, text="Button") f.pack_child(b, side='left') I haven't tried this, but I think it should work, however it might make the usage of the widget feel oddly unfamiliar. Otoh it should come in handy enough even for complex layouts with multiple layers of sub-frames (as long as these aren't ScrolledFrames themselves of course - definitely a flaw with this approach). Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Vulcans believe peace should not depend on force. -- Amanda, "Journey to Babel", stardate 3842.3 ___ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss ___ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss
Re: [Tkinter-discuss] Frame button binding
Hi, On Wed, 7 Sep 2016 06:31:06 + Vasilis Vlachoudiswrote: > Hi Michael, > > the ScrollFrame is of generic use as a normal frame class. So I don't > know apriori how many children it will have. I could set the bind > recursively in all winfo_children() and sub-children etc. after the > frame is populated but I though it will be an overkill. > I see your point of course, especially since probably other events than should be handled, too. Not sure if there is an easy solution to this, though. One possibility that comes to mind is adding custom geometry methods to the ScrolledFrame class that handle the bindings, like: def pack_child(self, child, **kw): child.pack(**kw) child.bind("", self.dragStart) Then you could conveniently do something like b = Button(f, text="Button") f.pack_child(b, side='left') I haven't tried this, but I think it should work, however it might make the usage of the widget feel oddly unfamiliar. Otoh it should come in handy enough even for complex layouts with multiple layers of sub-frames (as long as these aren't ScrolledFrames themselves of course - definitely a flaw with this approach). Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Vulcans believe peace should not depend on force. -- Amanda, "Journey to Babel", stardate 3842.3 ___ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss
Re: [Tkinter-discuss] Frame button binding
Hi, On Tue, 6 Sep 2016 09:00:45 + Vasilis Vlachoudiswrote: > 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. (...) Have you tried to simply add a binding for the event to the Frame's children, as in b = Button(f, text="Button") b.pack() b.bind("", dragStart) ? Best regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. No more blah, blah, blah! -- Kirk, "Miri", stardate 2713.6 ___ Tkinter-discuss mailing list Tkinter-discuss@python.org https://mail.python.org/mailman/listinfo/tkinter-discuss