开发者

How to use on_mouse_motion to move around a lable via pyglet?

开发者 https://www.devze.com 2022-12-15 00:54 出处:网络
How can one move a label around in the hello wor开发者_JAVA百科ld example using the on_mouse_motion function?

How can one move a label around in the hello wor开发者_JAVA百科ld example using the on_mouse_motion function?

The docs aren't clicking for me.

on_mouse-motion

hello_world_example.py


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()
0

精彩评论

暂无评论...
验证码 换一张
取 消