Package pyglet.app

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:

from pyglet import app
from pyglet import window

win = window.Window()
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 = app.EventLoop()

@event_loop.event
def on_window_close(window):
    event_loop.exit()

Since: pyglet 1.1

Classes

  WeakSet
Set of objects, referenced weakly.
  EventLoop
The main run loop of the application.

Functions

  run()
Begin processing events, scheduled functions and window updates.
  exit()
Exit the application event loop.

Variables

WeakSet displays = WeakSet()
Set of all open displays.
WeakSet windows = WeakSet()
Set of all open windows (including invisible windows).
EventLoop event_loop = None
The global event loop.

Function Details

run

run()

Begin processing events, scheduled functions and window updates.

This is a convenience function, equivalent to:

EventLoop().run()

exit

exit()

Exit the application event loop.

Causes the application event loop to finish, if an event loop is currently running. The application may not necessarily exit (for example, there may be additional code following the run invocation).

This is a convenience function, equivalent to:

event_loop.exit()

Variables Details

displays

Set of all open displays. Instances of 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.
Type:
WeakSet
Value:
WeakSet()

windows

Set of all open windows (including invisible windows). Instances of 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.
Type:
WeakSet
Value:
WeakSet()

event_loop

The global event loop. Set to the correct instance when an EventLoop is started.
Type:
EventLoop
Value:
None