[Tutor] Testing for mouse clicks
Phil
phillor9 at gmail.com
Sat Nov 7 19:40:29 EST 2020
On 8/11/20 10:16 am, Cameron Simpson wrote:
> Can you inspect your grid widget to determine its coordinates? Or
> inspect the button for its coordinates? If so, measure, construct a
> mapping of bounds to actions to take. Example:
>
>
> widget_map = {}
> for my_widget in enumerate-your-widgets-here:
> x0, dx, y0, dy = my_widget.bounds()
> widget_map[x0, y0, x0+dx, y0+dy] = my_widget
> ...
> # find the widget and call its on_clicked method
> for (x0, x1, y0, y1), my_widget in widget_map.items():
> if x0 <= x < x1 and y0 < y <= y1:
> my_widget.on_clicked(...)
> break
>
Thank you Cameron, I would never have thought of using a for_loop with
multiple variables. I'll experiment with this idea and see what I can
come up with.
--
Regards,
Phil
More information about the Tutor
mailing list