Search code examples
pythonpyglet

python stop when pyglet.app.run() applied


I'm a beginner. I tried to show some pictures by pyglet and it works will. But the whole program stopped after the picture showed in window. The main code is like

str="test"

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

pyglet.app.run()
print(str)

The code is simplified as the program's concept. The issue is the code after pyglet.app.run() cannot be run. Is there any way to solve this issue? And I also want to keep the picture window stay. Thanks a lot for the help.


Solution

  • Pyglet has its own internal loop determined by pyglet.app.run(). So all the code present later is not executed unless you exit the loop. If you want to insert new things, you must either use Pyglet's default functions, or create new functions that are called in the Pyglet loop.