如何通过 pyglet 使用 on_mouse_motion 在标签上移动?

发布于 2024-08-15 19:46:42 字数 329 浏览 2 评论 0原文

如何使用 on_mouse_motion 函数在 hello world 示例中移动标签?

这些文档不适合我。

on_mouse-motion

hello_world_example.py

How can one move a label around in the hello world example using the on_mouse_motion function?

The docs aren't clicking for me.

on_mouse-motion

hello_world_example.py

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

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

发布评论

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

评论(1

流绪微梦 2024-08-22 19:46:42

想通了:不知道这是否是最有效的解决方案。

编辑->仅针对 xy 进行固定。

#!/usr/bin/env python

import pyglet

window = pyglet.window.Window()
fps_display = pyglet.clock.ClockDisplay()
label = pyglet.text.Label('Hello World!',font_name='Arial',font_size=36, x=0, y=0)

@window.event                       
def on_mouse_motion(x, y, dx, dy):
    window.clear()
    label.x = x
    label.y = y

fps_display = pyglet.clock.ClockDisplay()

@window.event
def on_draw():
    fps_display.draw()
    label.draw()

pyglet.app.run()

Figured it out: Don't know if this is the most efficient solution though.

EDIT -> fixed for just xy.

#!/usr/bin/env python

import pyglet

window = pyglet.window.Window()
fps_display = pyglet.clock.ClockDisplay()
label = pyglet.text.Label('Hello World!',font_name='Arial',font_size=36, x=0, y=0)

@window.event                       
def on_mouse_motion(x, y, dx, dy):
    window.clear()
    label.x = x
    label.y = y

fps_display = pyglet.clock.ClockDisplay()

@window.event
def on_draw():
    fps_display.draw()
    label.draw()

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