views:

77

answers:

2

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

+1  A: 

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()
Nazarius Kappertaal
Better to make the label just once, and set its x and y properties in the on_mouse_motion call.
Kylotan
A: 

Good example, I suggest moving the window.clear() statement to after def on_draw(): to ensure the clock stays visible when the mouse is not moved.

William