commit f3b25cf9cf22a31dab6e77357d67228b1f589106 parent 8438672541e7c7df7416a72af331e4882b5ddd77 Author: Yuval Langer <yuval.langer@gmail.com> Date: Thu, 27 Jan 2022 08:08:37 +0200 Add Python + GTK + OpenCV post. Diffstat:
A | content/2022-01-27-opencv-and-gtk.md | | | 34 | ++++++++++++++++++++++++++++++++++ |
1 file changed, 34 insertions(+), 0 deletions(-)
diff --git a/content/2022-01-27-opencv-and-gtk.md b/content/2022-01-27-opencv-and-gtk.md @@ -0,0 +1,34 @@ +title: Finding mouse location in Python + GTK + OpenCV. +date: 2022-01-27 + +Expanding on the tutorial: + +<https://nofurtherquestions.wordpress.com/2017/03/03/python-3-5-gtk-3-glade-and-opencv/> + +it originally had shown the following structure: + +- window1 (GtkWindow) + - box1 (GtkBox) + - grayscaleButton (GtkToggleButton) + - image - (GtkImage) + +but if you want to find the mouse location, put your GtkImage inside a GtkEventBox: + +- window1 (GtkWindow) + - box1 (GtkBox) + - grayscaleButton (GtkToggleButton) + - eventbox - (GtkEventBox) + - image - (GtkImage) + +and in `eventbox` set the `Common -> Events -> Pointer Motion` so you can add a handler to the `motion-notify-event` event. + +Now you can write your handler: + +``` +def on_motion_notify_event(self, *args): + global current_mouse_location + + event = args[1] + + current_mouse_location = event.x, event.y +```