[Tkinter-discuss] Frame button binding

Michael Lange klappnase at web.de
Wed Sep 7 05:53:37 EDT 2016


Hi,

On Wed, 7 Sep 2016 06:31:06 +0000
Vasilis Vlachoudis <Vasilis.Vlachoudis at 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 <Button-2> 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("<Button-2>", 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


More information about the Tkinter-discuss mailing list