From msa01 at bitflipper.ca Sun Sep 4 09:56:20 2016 From: msa01 at bitflipper.ca (Cam Farnell) Date: Sun, 4 Sep 2016 10:56:20 -0300 Subject: [Tkinter-discuss] Dealing with a Tk reference In-Reply-To: References: Message-ID: <57CC2804.2060904@bitflipper.ca> I've been using New Mexico Tech example code from here: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/menu-toplevel.html to create a top-level menu. The example code is: top = self.winfo_toplevel() self.menuBar = tk.Menu(top) top['menu'] = self.menuBar self.subMenu = tk.Menu(self.menuBar) self.menuBar.add_cascade(label='Help', menu=self.subMenu) self.subMenu.add_command(label='About', command=self.__aboutHandler) and that works just fine. In particular it creates a Menu using: self.menuBar = tk.Menu(top) and then assigns it to the top-level using: top['menu'] = self.menuBar In my application it is not convenient to keep the reference to the Menu in self.menuBar. Later when it comes time to add another another cascade to the menu I was hoping to be able access the menu bar using: menuBar = top['menu'] but in fact having done that, menuBar not a tk.Menu object as I was hoping but rather a string, such as ".3070843372L", which is presumably a reference to a tk object. So my question is: how to use the string to access the corresponding tk.Menu object? There's probably some magic way to do that but a bunch of internet searching didn't turn it up. Thanks Cam From klappnase at web.de Sun Sep 4 10:38:35 2016 From: klappnase at web.de (Michael Lange) Date: Sun, 4 Sep 2016 16:38:35 +0200 Subject: [Tkinter-discuss] Dealing with a Tk reference In-Reply-To: <57CC2804.2060904@bitflipper.ca> References: <57CC2804.2060904@bitflipper.ca> Message-ID: <20160904163835.dd07f5ca9af89d786e6f0eb7@web.de> Hi, On Sun, 4 Sep 2016 10:56:20 -0300 Cam Farnell wrote: (...) > In my application it is not convenient to keep the reference to the > Menu in self.menuBar. Later when it comes time to add another another > cascade to the menu I was hoping to be able access the menu bar using: > > menuBar = top['menu'] > > but in fact having done that, menuBar not a tk.Menu object as I was > hoping but rather a string, such as ".3070843372L", which is presumably > a reference to a tk object. > > So my question is: how to use the string to access the corresponding > tk.Menu object? There's probably some magic way to do that but a bunch > of internet searching didn't turn it up. to convert the widget name into a Widget object you will need the nametowidget method, as in menubar = top.nametowidget(top['menu']) Best regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. No one may kill a man. Not for any purpose. It cannot be condoned. -- Kirk, "Spock's Brain", stardate 5431.6 From Vasilis.Vlachoudis at cern.ch Tue Sep 6 05:00:45 2016 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Tue, 6 Sep 2016 09:00:45 +0000 Subject: [Tkinter-discuss] Frame button binding Message-ID: <0BC70B5D93E054469872FFD0FE07220E018322184A@CERNXCHG53.cern.ch> 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? Thanks in advance Vasilis From klappnase at web.de Tue Sep 6 17:24:29 2016 From: klappnase at web.de (Michael Lange) Date: Tue, 6 Sep 2016 23:24:29 +0200 Subject: [Tkinter-discuss] Frame button binding In-Reply-To: <0BC70B5D93E054469872FFD0FE07220E018322184A@CERNXCHG53.cern.ch> References: <0BC70B5D93E054469872FFD0FE07220E018322184A@CERNXCHG53.cern.ch> Message-ID: <20160906232429.e7215ffe893a602a6ecc8791@web.de> Hi, 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. (...) 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 From Vasilis.Vlachoudis at cern.ch Tue Sep 6 03:41:41 2016 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Tue, 6 Sep 2016 07:41:41 +0000 Subject: [Tkinter-discuss] Toplevel background Message-ID: <0BC70B5D93E054469872FFD0FE07220E0183221758@CERNXCHG53.cern.ch> Hi all, I have a window which I make full screen with the option tk = Tk() tk.attributes("-fullscreen", True) c = Canvas(tk, background="Black") c.pack(expand=YES, fill=BOTH, padx=0, pady=0) and displays a full screen "Black" canvas. despite I h ave padx=pady=0 I always get 1 pixel White frame all around. I believe that it comes from the toplevel window. How can I remove this frame or change its color to black Thanks in advance Vasilis From johnmc at velseis.com Tue Sep 6 19:54:12 2016 From: johnmc at velseis.com (johnmc) Date: Wed, 7 Sep 2016 09:54:12 +1000 Subject: [Tkinter-discuss] Toplevel background In-Reply-To: <0BC70B5D93E054469872FFD0FE07220E0183221758@CERNXCHG53.cern.ch> References: <0BC70B5D93E054469872FFD0FE07220E0183221758@CERNXCHG53.cern.ch> Message-ID: <20160906235003.M94004@velseis.com> On Tue, 6 Sep 2016 07:41:41 +0000, Vasilis Vlachoudis wrote > Hi all, > > I have a window which I make full screen with the option > > tk = Tk() > tk.attributes("-fullscreen", True) > c = Canvas(tk, background="Black") > c.pack(expand=YES, fill=BOTH, padx=0, pady=0) > > and displays a full screen "Black" canvas. despite > I h ave padx=pady=0 I always get 1 pixel White frame all around. > I believe that it comes from the toplevel window. How can I remove this frame > or change its color to black > > Thanks in advance > Vasilis Hi Vasilis, the 1 pixel white frame is coming from the canvas widget being in focus. Simply change to : c = Canvas(tk, background="Black", highlightthickness=0) Regards, John -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From klappnase at web.de Wed Sep 7 05:53:37 2016 From: klappnase at web.de (Michael Lange) Date: Wed, 7 Sep 2016 11:53:37 +0200 Subject: [Tkinter-discuss] Frame button binding In-Reply-To: <0BC70B5D93E054469872FFD0FE07220E0183223C69@CERNXCHG53.cern.ch> References: <0BC70B5D93E054469872FFD0FE07220E018322184A@CERNXCHG53.cern.ch> <20160906232429.e7215ffe893a602a6ecc8791@web.de> <0BC70B5D93E054469872FFD0FE07220E0183223C69@CERNXCHG53.cern.ch> Message-ID: <20160907115337.3309ac2334ec9f29a031293f@web.de> Hi, On Wed, 7 Sep 2016 06:31:06 +0000 Vasilis Vlachoudis 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 From Vasilis.Vlachoudis at cern.ch Wed Sep 7 06:21:02 2016 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Wed, 7 Sep 2016 10:21:02 +0000 Subject: [Tkinter-discuss] Frame button binding In-Reply-To: <20160907115337.3309ac2334ec9f29a031293f@web.de> References: <0BC70B5D93E054469872FFD0FE07220E018322184A@CERNXCHG53.cern.ch> <20160906232429.e7215ffe893a602a6ecc8791@web.de> <0BC70B5D93E054469872FFD0FE07220E0183223C69@CERNXCHG53.cern.ch>, <20160907115337.3309ac2334ec9f29a031293f@web.de> Message-ID: <0BC70B5D93E054469872FFD0FE07220E01832255D8@CERNXCHG53.cern.ch> 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.ch at python.org] on behalf of Michael Lange [klappnase at web.de] Sent: Wednesday, September 07, 2016 11:53 To: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] Frame button binding Hi, On Wed, 7 Sep 2016 06:31:06 +0000 Vasilis Vlachoudis 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 at python.org https://mail.python.org/mailman/listinfo/tkinter-discuss From klappnase at web.de Wed Sep 7 06:31:35 2016 From: klappnase at web.de (Michael Lange) Date: Wed, 7 Sep 2016 12:31:35 +0200 Subject: [Tkinter-discuss] Frame button binding In-Reply-To: <0BC70B5D93E054469872FFD0FE07220E01832255D8@CERNXCHG53.cern.ch> References: <0BC70B5D93E054469872FFD0FE07220E018322184A@CERNXCHG53.cern.ch> <20160906232429.e7215ffe893a602a6ecc8791@web.de> <0BC70B5D93E054469872FFD0FE07220E0183223C69@CERNXCHG53.cern.ch> <20160907115337.3309ac2334ec9f29a031293f@web.de> <0BC70B5D93E054469872FFD0FE07220E01832255D8@CERNXCHG53.cern.ch> Message-ID: <20160907123135.ac9df2979820ab26cb115f77@web.de> Hi, On Wed, 7 Sep 2016 10:21:02 +0000 Vasilis Vlachoudis 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 From Vasilis.Vlachoudis at cern.ch Wed Sep 7 10:01:19 2016 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Wed, 7 Sep 2016 14:01:19 +0000 Subject: [Tkinter-discuss] Frame button binding In-Reply-To: <20160907123135.ac9df2979820ab26cb115f77@web.de> References: <0BC70B5D93E054469872FFD0FE07220E018322184A@CERNXCHG53.cern.ch> <20160906232429.e7215ffe893a602a6ecc8791@web.de> <0BC70B5D93E054469872FFD0FE07220E0183223C69@CERNXCHG53.cern.ch> <20160907115337.3309ac2334ec9f29a031293f@web.de> <0BC70B5D93E054469872FFD0FE07220E01832255D8@CERNXCHG53.cern.ch>, <20160907123135.ac9df2979820ab26cb115f77@web.de> Message-ID: <0BC70B5D93E054469872FFD0FE07220E01832259CD@CERNXCHG53.cern.ch> 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.ch at python.org] on behalf of Michael Lange [klappnase at web.de] Sent: Wednesday, September 07, 2016 12:31 To: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] Frame button binding Hi, On Wed, 7 Sep 2016 10:21:02 +0000 Vasilis Vlachoudis 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 at python.org https://mail.python.org/mailman/listinfo/tkinter-discuss From klappnase at web.de Wed Sep 7 16:47:59 2016 From: klappnase at web.de (Michael Lange) Date: Wed, 7 Sep 2016 22:47:59 +0200 Subject: [Tkinter-discuss] Frame button binding In-Reply-To: <0BC70B5D93E054469872FFD0FE07220E01832259CD@CERNXCHG53.cern.ch> References: <0BC70B5D93E054469872FFD0FE07220E018322184A@CERNXCHG53.cern.ch> <20160906232429.e7215ffe893a602a6ecc8791@web.de> <0BC70B5D93E054469872FFD0FE07220E0183223C69@CERNXCHG53.cern.ch> <20160907115337.3309ac2334ec9f29a031293f@web.de> <0BC70B5D93E054469872FFD0FE07220E01832255D8@CERNXCHG53.cern.ch> <20160907123135.ac9df2979820ab26cb115f77@web.de> <0BC70B5D93E054469872FFD0FE07220E01832259CD@CERNXCHG53.cern.ch> Message-ID: <20160907224759.901347b8c9e0cf7baedf79f2@web.de> Hi, On Wed, 7 Sep 2016 14:01:19 +0000 Vasilis Vlachoudis 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 From Vasilis.Vlachoudis at cern.ch Wed Sep 7 02:31:06 2016 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Wed, 7 Sep 2016 06:31:06 +0000 Subject: [Tkinter-discuss] Frame button binding In-Reply-To: <20160906232429.e7215ffe893a602a6ecc8791@web.de> References: <0BC70B5D93E054469872FFD0FE07220E018322184A@CERNXCHG53.cern.ch>, <20160906232429.e7215ffe893a602a6ecc8791@web.de> Message-ID: <0BC70B5D93E054469872FFD0FE07220E0183223C69@CERNXCHG53.cern.ch> 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.ch at python.org] on behalf of Michael Lange [klappnase at web.de] Sent: Tuesday, September 06, 2016 23:24 To: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] Frame button binding Hi, 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. (...) 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 at python.org https://mail.python.org/mailman/listinfo/tkinter-discuss From johnmc at velseis.com Thu Sep 8 06:21:02 2016 From: johnmc at velseis.com (johnmc) Date: Thu, 8 Sep 2016 20:21:02 +1000 Subject: [Tkinter-discuss] Frame button binding In-Reply-To: <0BC70B5D93E054469872FFD0FE07220E018322184A@CERNXCHG53.cern.ch> References: <0BC70B5D93E054469872FFD0FE07220E018322184A@CERNXCHG53.cern.ch> Message-ID: <20160908101050.M39431@velseis.com> 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("", 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. From Vasilis.Vlachoudis at cern.ch Fri Sep 9 03:24:57 2016 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Fri, 9 Sep 2016 07:24:57 +0000 Subject: [Tkinter-discuss] Frame button binding In-Reply-To: <20160907224759.901347b8c9e0cf7baedf79f2@web.de> References: <0BC70B5D93E054469872FFD0FE07220E018322184A@CERNXCHG53.cern.ch> <20160906232429.e7215ffe893a602a6ecc8791@web.de> <0BC70B5D93E054469872FFD0FE07220E0183223C69@CERNXCHG53.cern.ch> <20160907115337.3309ac2334ec9f29a031293f@web.de> <0BC70B5D93E054469872FFD0FE07220E01832255D8@CERNXCHG53.cern.ch> <20160907123135.ac9df2979820ab26cb115f77@web.de> <0BC70B5D93E054469872FFD0FE07220E01832259CD@CERNXCHG53.cern.ch>, <20160907224759.901347b8c9e0cf7baedf79f2@web.de> Message-ID: <0BC70B5D93E054469872FFD0FE07220E018322C674@CERNXCHG53.cern.ch> for the moment I was using the event.widget and compare it as a string it is has as prefix the scrolled frame, but I was wondering if there was a more elegant way. V. ________________________________________ From: Tkinter-discuss [tkinter-discuss-bounces+vasilis.vlachoudis=cern.ch at python.org] on behalf of Michael Lange [klappnase at web.de] Sent: Wednesday, September 07, 2016 22:47 To: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] Frame button binding Hi, On Wed, 7 Sep 2016 14:01:19 +0000 Vasilis Vlachoudis 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 at python.org https://mail.python.org/mailman/listinfo/tkinter-discuss From Vasilis.Vlachoudis at cern.ch Fri Sep 9 04:40:50 2016 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Fri, 9 Sep 2016 08:40:50 +0000 Subject: [Tkinter-discuss] Frame button binding In-Reply-To: <20160907224759.901347b8c9e0cf7baedf79f2@web.de> References: <0BC70B5D93E054469872FFD0FE07220E018322184A@CERNXCHG53.cern.ch> <20160906232429.e7215ffe893a602a6ecc8791@web.de> <0BC70B5D93E054469872FFD0FE07220E0183223C69@CERNXCHG53.cern.ch> <20160907115337.3309ac2334ec9f29a031293f@web.de> <0BC70B5D93E054469872FFD0FE07220E01832255D8@CERNXCHG53.cern.ch> <20160907123135.ac9df2979820ab26cb115f77@web.de> <0BC70B5D93E054469872FFD0FE07220E01832259CD@CERNXCHG53.cern.ch>, <20160907224759.901347b8c9e0cf7baedf79f2@web.de> Message-ID: <0BC70B5D93E054469872FFD0FE07220E018322C956@CERNXCHG53.cern.ch> 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.ch at python.org] on behalf of Michael Lange [klappnase at web.de] Sent: Wednesday, September 07, 2016 22:47 To: tkinter-discuss at python.org Subject: Re: [Tkinter-discuss] Frame button binding Hi, On Wed, 7 Sep 2016 14:01:19 +0000 Vasilis Vlachoudis 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 at python.org https://mail.python.org/mailman/listinfo/tkinter-discuss From Vasilis.Vlachoudis at cern.ch Fri Sep 9 03:26:39 2016 From: Vasilis.Vlachoudis at cern.ch (Vasilis Vlachoudis) Date: Fri, 9 Sep 2016 07:26:39 +0000 Subject: [Tkinter-discuss] Frame button binding In-Reply-To: <20160908101050.M39431@velseis.com> References: <0BC70B5D93E054469872FFD0FE07220E018322184A@CERNXCHG53.cern.ch>, <20160908101050.M39431@velseis.com> Message-ID: <0BC70B5D93E054469872FFD0FE07220E018322C6A9@CERNXCHG53.cern.ch> 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 [johnmc at velseis.com] Sent: Thursday, September 08, 2016 12:21 To: Vasilis Vlachoudis; tkinter-discuss at 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("", 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.