使用 pygtk.Window 在窗口的任何部分单击事件

发布于 2024-12-28 00:34:23 字数 250 浏览 2 评论 0 原文

我正在使用 pygtk 和 Glade 来制作一个简单的程序,该程序(到目前为止)包括:

GUI: 一个 4x4 的网格,每个网格都显示一个名称。 网格下方有一个文本条目。 该程序以全屏方式运行。

行为: 每个名称都可以无限循环“选择”10 秒。 “可选择”意味着无论用户在何处单击,都会选择运行 10 秒时间的名称并将其放在 TextEntry 上。

我已经制作了 GUI,但不知道如何处理它来检测屏幕上任意位置的点击。有什么帮助吗?

I am using pygtk with glade to make a simple program which (by now) consists on:

GUI:
A grid 4x4, each one showing an name.
Under the grid goes a text Entry.
The program runs in fullscreen.

BEHAVIOR:
Each name will be "selectable" for 10secs in an infinite loop. "selectable" means that wherever the user makes a click the name which 10secs time is running is selected and put on the TextEntry.

I already made the GUI, but don't know how to handle it for detecting the click anywhere on the screen. Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒人说梦 2025-01-04 00:34:23

要检测屏幕上任意位置的点击,您可以连接 按钮按下事件。请注意,这是一个 gdk 事件,您必须使用 add_events 方法。

下面这个小程序应该有用:

import gtk

def callback(window, event):
    assert event.type == gtk.gdk.BUTTON_PRESS
    print 'Clicked at x={0}, y={0}'.format(event.x, event.y)

window = gtk.Window()
window.add_events(gtk.gdk.BUTTON_PRESS_MASK)
window.connect('button-press-event', callback)
window.connect('destroy', lambda w: gtk.main_quit())
window.show_all()

gtk.main()

To detect a click anywhere on the screen you can connect a callback for the button-press-event. Note that this is a gdk event and you must add this event to the mask with the add_events method.

The following small program should be useful:

import gtk

def callback(window, event):
    assert event.type == gtk.gdk.BUTTON_PRESS
    print 'Clicked at x={0}, y={0}'.format(event.x, event.y)

window = gtk.Window()
window.add_events(gtk.gdk.BUTTON_PRESS_MASK)
window.connect('button-press-event', callback)
window.connect('destroy', lambda w: gtk.main_quit())
window.show_all()

gtk.main()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文