In the following block, clicking on a_frame
triggers the event handler on_frame_click
, but clicking on a_label
which is a child of a
I can't seem to find a direct method of automatically binding to child widgets (though there are methods of binding to an entire class of widgets and to all widgets in an application), but something like this would be easy enough.
def bind_tree(widget, event, callback, add=''):
"Binds an event to a widget and all its descendants."
widget.bind(event, callback, add)
for child in widget.children.values():
bind_tree(child, event, callback, replace_callback)
Just thought of this, but you could also put a transparent widget the size of a_frame
on top of everything as a child of a_frame
and bind the event to that, and then you could refer to
a_frame
as e.widget.master
in the callback in order to make it reusable if necessary. That'd likely do what you want.