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
||Exit the application event loop.|
||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.
displays= <pyglet.app.WeakSet object>¶
Set of all open displays. Instances of
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
event_loop= <pyglet.app.base.EventLoop object>¶
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.
platform_event_loop= <pyglet.app.base.PlatformEventLoop object>¶
Abstract class, implementation depends on platform.
Since pyglet 1.2
windows= <pyglet.app.WeakSet object>¶
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.