Gtk:如何检测EventBox上的鼠标位置? [英] Gtk: How to detect the mouse position over EventBox?
问题描述
我一直试图用Python编写简单的CAD应用程序.我正在修补pyglet,得到了一些结果:,但是我决定切换回Gtk,然后撞墙了:
I have been trying to write simple CAD application in Python. I was tinkering with pyglet, got some results: , but I decided to switch back to Gtk and I hit the wall:
我无法将鼠标指针放置在EventBox上(使用pyglet,它是图片中窗口应用程序左下角的标签).为此设计了什么信号?还是应该使用其他方法?
I cannot get the mouse pointer position over the EventBox (with pyglet it was the label in the bottom left corner of the window app in the picture). What signal is designed for it? Or should I use another approach?
我将不胜感激任何信息或资源.提前致谢.
I will appreciate any piece of information or resources. Thanks in advance.
推荐答案
问题:如何检测EventBox上的鼠标位置?
Question: How to detect the mouse position over EventBox?
- 操作方法在事件框中捕获事件以检测鼠标在gtk中的运动
- Gtk.EventBox
- how-to-capture-event-on-event-box-to-detect-mouse-movement-in-gtk
- Gtk.EventBox
Gtk.EventBox
小部件是Gtk.Bin
的子类,它也有自己的窗口.这很有用,因为它允许您捕获没有自己窗口的窗口小部件的事件.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
中的events
添加到self
的事件掩码中.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 指针(通常是鼠标)已经移动
- GDK_MOTION_NOTIFY the pointer (usually a mouse) has moved
Gtk.EventBox
应该有标志,而不是窗口!The
Gtk.EventBox
should have got the flag, not the window!box = Gtk.EventBox() box.connect("motion-notify-event", self.on_mouse_move) box.add_events(Gdk.EventMask.POINTER_MOTION_MASK)
这篇关于Gtk:如何检测EventBox上的鼠标位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!