pyglet.app
Application-wide functionality.
Applications
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()
Events
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()
Added in version 1.1.
Classes
- class EventLoop
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 callspyglet.window.Window.on_draw()andpyglet.window.Window.flip()to update window contents.Applications can subclass
EventLoopand override certain methods to integrate another framework’s run loop, or to customise processing in some other way. You should not in general overriderun(), as this method contains platform-specific code that ensures the application remains responsive to the user while keeping CPU usage to a minimum.Methods
Events
Attributes
- has_exit
Flag indicating if the event loop will exit in the next iteration.
When set, all waiting threads are interrupted.
:see
sleep():Thread-safe since pyglet 1.2.
Methods (internal)
- classmethod __new__(*args, **kwargs)
- class PlatformEventLoop
Abstract class, implementation depends on platform.
Added in version 1.2.
Functions
Attributes
- event_loop = <pyglet.app.base.EventLoop object>
The global event loop. Applications can replace this with their own subclass of
EventLoopbefore callingEventLoop.run().
- platform_event_loop = <pyglet.app.base.PlatformEventLoop object>
The platform-dependent event loop. Applications are strongly discouraged from subclassing or replacing this
PlatformEventLoopobject.
- windows = set()
Set of all open windows (including invisible windows). Instances of
pyglet.window.Windoware 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.