Hi,

Thus spoketh Vasilis Vlachoudis <vasilis.vlachou...@cern.ch> 
unto us on Tue, 21 Dec 2010 08:58:20 +0000:

> Hi all,
> 
> Based on the previous threads I added the nice scrolled.py
> implementation of a ScrollFrame in my application and now I wanted to
> bind the Button-4&5 and MouseWheel events to the scrolled frame. My
> frames are a bit crowded therefore the real area that belongs to the
> client-scrolledframe is minimal the rest is buttons labels lists etc...
> Therefore when I bind the <Button-4>... on the frame, I never get the
> events when the cursor is above a label or any other widget (which is
> most of the time). For the moment after the creation of each frame I am
> calling a similar like the following function recursively
> 
> def bind_childs(w):
>     if w.bind("<4>"): return
>     w.bind("<4>", button4)
>     w.bind("<5>", button5)
>     for child in  w.winfo_children():
>         child.bind("<4>", button4)
>         child.bind("<5>", button5)
> 
> however I don't find it as a elegant and neat solution.
> Is there a way (like bind_all) to bind all children or to get the event
> if is is not handled by any of the children?

I don't think it's that bad at all. If you have a lot of frames and
children, maybe it is a bit nicer to define widget classes that save you
to explicitely apply the bindings for any of your Frames and their
children, like:

class SLabel(Label):
    def __init__(self, *args, **kw):
        Label.__init__(self, *args, **kw)
        for seq in ('<4>', '<5>'):
            if self.master.bind(seq):
                self.bind(seq, self.master.bind(seq))

Regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Intuition, however illogical, is recognized as a command prerogative.
                -- Kirk, "Obsession", stardate 3620.7
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to