我一直在尝试用 Python 编写简单的 CAD 应用程序。我正在修改 pyglet,得到了一些结果: ,但我决定切换回 Gtk,结果碰壁了:
我无法获取EventBox上的鼠标指针位置(对于pyglet,它是图片中窗口应用程序左下角的标签)。为此设计了什么信号?或者我应该使用另一种方法?
我将不胜感激任何信息或资源。提前致谢。
最佳答案
Question: How to detect the mouse position over EventBox?
- how-to-capture-event-on-event-box-to-detect-mouse-movement-in-gtk
- Gtk.EventBox
The
Gtk.EventBox
widget is a subclass ofGtk.Bin
which also has its own window. It is useful since it allows you to catch events for widgets which do not have their own window. - Gtk.Widget.add_events(events)
Adds the
events
in the bitfieldevents
to the event mask forself
. - Gdk.EventMask
A set of bit-flags to indicate which events a window is to receive.
- GDK_MOTION_NOTIFY the pointer (usually a mouse) has moved
Gtk.EventBox
应该获得标志,而不是窗口!
box = Gtk.EventBox()
box.connect("motion-notify-event", self.on_mouse_move)
box.add_events(Gdk.EventMask.POINTER_MOTION_MASK)
关于python - Gtk:如何检测EventBox上的鼠标位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58683788/