0

I am new to pyglet and I have a question about the image on the screen update. Necessary each time the mouse pressed to change the count, but I have all the time is zero, where did I go wrong and how can I fix it?

from pyglet.window import mouse
from pyglet import *
import pyglet

window = pyglet.window.Window(800, 600)
n = 0
label = pyglet.text.Label(str(n), x = window.width/2, y = window.width/2 )

@window.event
def on_mouse_press(x, y, button, modifiers):
    if button == mouse.LEFT:
        global n
        n += 1

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

def update():
    pass

pyglet.app.run()
pyglet.clock.schedule_interval(update, 1/30.0)

Thank you!

Belogurow
  • 23
  • 1
  • 8

1 Answers1

0

You need to create again the label in order to change its value (or better modify the label.text attribute)! Actually you didn't pass n to pyglet.text.Label but a string created "on the fly" containing that value.

@window.event
def on_mouse_press(x, y, button, modifiers):
    if button == mouse.LEFT:
        global n
        n += 1
        label.text = str(n)

Hope it helps.

cdonts
  • 9,304
  • 4
  • 46
  • 72
  • I'm sorry ,I take care with the `label` , but how in the method `on_mouse_press` I can create a new primitive like `GL_POINTS` with the coordinates `(x, y)`? – Belogurow Mar 02 '16 at 11:12
  • @Artur123 I'm afraid I can't help you with that, I never used Pyglet nor OpenGL. – cdonts Mar 02 '16 at 17:09