Application-wide functionality.
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()
Note
Since pyglet 1.1
event_loop is the global event loop. Applications can replace this with their own subclass of EventLoop before calling EventLoop.run().
platform_event_loop is the platform-dependent event loop. Applications must not subclass or replace this PlatformEventLoop object.
EventLoop | The main run loop of the application. |
PlatformEventLoop | Abstract class, implementation depends on platform. |
WeakSet | Set of objects, referenced weakly. |
AppException |
exit() | Exit the application event loop. |
run() | Begin processing events, scheduled functions and window updates. |
str(object=’‘) -> string
Return a nice string representation of the object. If the argument is a string, the return value is the same object.
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.
Warning
Deprecated. Use pyglet.canvas.get_display().
Type: | WeakSet |
---|
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.
Note
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.
Defined