Most applications need only call run() after creating one or more windows to begin processing events. For example, a simple application consisting of one window is:
import pyglet win = pyglet.window.Window() pyglet.app.run()
To handle events on the main event loop, instantiate it manually. The following example exits the application as soon as any window is closed (the default policy is to wait until all windows are closed):
event_loop = pyglet.app.EventLoop() @event_loop.event def on_window_close(window): event_loop.exit()
Since pyglet 1.1
|EventLoop||The main run loop of the application.|
|PlatformEventLoop||Abstract class, implementation depends on platform.|
|WeakSet||Set of objects, referenced weakly.|
|exit()||Exit the application event loop.|
|run()||Begin processing events, scheduled functions and window updates.|
Set of all open displays. Instances of pyglet.canvas.Display are automatically added to this set upon construction. The set uses weak references, so displays are removed from the set when they are no longer referenced.
Deprecated. Use pyglet.canvas.get_display().
The main run loop of the application.
Calling run begins the application event loop, which processes operating system events, calls pyglet.clock.tick to call scheduled functions and calls pyglet.window.Window.on_draw and pyglet.window.Window.flip to update window contents.
Applications can subclass EventLoop and override certain methods to integrate another framework’s run loop, or to customise processing in some other way. You should not in general override run, as this method contains platform-specific code that ensures the application remains responsive to the user while keeping CPU usage to a minimum.
Abstract class, implementation depends on platform.
Since pyglet 1.2
Set of all open windows (including invisible windows). Instances of pyglet.window.Window are automatically added to this set upon construction. The set uses weak references, so windows are removed from the set when they are no longer referenced or are closed explicitly.