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()

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.

Classes

EventLoop The main run loop of the application.
PlatformEventLoop Abstract class, implementation depends on platform.
WeakSet Set of objects, referenced weakly.

Exceptions

AppException

Functions

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

Variables

displays = <pyglet.app.WeakSet object at 0x99e260c>

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
event_loop = <pyglet.app.base.EventLoop object at 0x99e2d4c>

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 at 0x99ea6ac>

Abstract class, implementation depends on platform.

Note

Since pyglet 1.2

windows = <pyglet.app.WeakSet object at 0x99e26ac>

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.

Notes

Defined

  • base
  • sys
  • weakref

Table Of Contents

Previous topic

get_platform Function

Next topic

EventLoop Class