Ok, here is a complete working example in pyglet. It displays the text "hello world", which takes a random walk around the window and resets the screenshot (using the same line of code that you sent) every time you press a key.
import pyglet, random window = pyglet.window.Window() label = pyglet.text.Label('Hello, world', font_name='Times New Roman', font_size=36, x=window.width//2, y=window.height//2, anchor_x='center', anchor_y='center') @window.event def on_draw(): window.clear() label.draw() @window.event def on_key_press(symbol, modifiers): pyglet.image.get_buffer_manager().get_color_buffer().save('screenshot.png') def update(dt): label.x += random.randint(-10, 10) label.y += random.randint(-10, 10) pyglet.clock.schedule_interval(update, 0.1) pyglet.app.run()
Taking a screenshot does not stop the event loop. The event loop in pyglet is just lazy and tries to do as little work as possible. You need to plan the execution of the function if you want everything to continue. Otherwise, he will wait for the event to which the listener is connected. (Your code should listen for the mouse event, so it resumes when the mouse is clicked.)
Short answer, I suspect you will need pyglet.clock.schedule_interval(...) .
tangentstorm
source share