Window Class

Inheritance diagram of Window

class Window(width=None, height=None, caption=None, resizable=False, style=None, fullscreen=False, visible=True, vsync=True, display=None, screen=None, config=None, context=None, mode=None)

Platform-independent application window.

A window is a “heavyweight” object occupying operating system resources. The “client” or “content” area of a window is filled entirely with an OpenGL viewport. Applications have no access to operating system widgets or controls; all rendering must be done via OpenGL.

Windows may appear as floating regions or can be set to fill an entire screen (fullscreen). When floating, windows may appear borderless or decorated with a platform-specific frame (including, for example, the title bar, minimize and close buttons, resize handles, and so on).

While it is possible to set the location of a window, it is recommended that applications allow the platform to place it according to local conventions. This will ensure it is not obscured by other windows, and appears on an appropriate screen for the user.

To render into a window, you must first call switch_to, to make it the current OpenGL context. If you use only one window in the application, there is no need to do this.

Variables:has_exit

True if the user has attempted to close the window.

Warning

Deprecated. Windows are closed immediately by the default on_close handler when pyglet.app.event_loop is being used.

Constructor:

__init__(width=None, height=None, caption=None, resizable=False, style=None, fullscreen=False, visible=True, vsync=True, display=None, screen=None, config=None, context=None, mode=None)

Create a window.

All parameters are optional, and reasonable defaults are assumed where they are not specified.

The display, screen, config and context parameters form a hierarchy of control: there is no need to specify more than one of these. For example, if you specify screen the display will be inferred, and a default config and context will be created.

config is a special case; it can be a template created by the user specifying the attributes desired, or it can be a complete config as returned from Screen.get_matching_configs or similar.

The context will be active as soon as the window is created, as if switch_to was just called.

Parameters:
  • width (int) – Width of the window, in pixels. Defaults to 640, or the screen width if fullscreen is True.
  • height (int) – Height of the window, in pixels. Defaults to 480, or the screen height if fullscreen is True.
  • caption (str or unicode) – Initial caption (title) of the window. Defaults to sys.argv[0].
  • resizable (bool) – If True, the window will be resizable. Defaults to False.
  • style (int) – One of the WINDOW_STYLE_* constants specifying the border style of the window.
  • fullscreen (bool) – If True, the window will cover the entire screen rather than floating. Defaults to False.
  • visible (bool) – Determines if the window is visible immediately after creation. Defaults to True. Set this to False if you would like to change attributes of the window before having it appear to the user.
  • vsync (bool) – If True, buffer flips are synchronised to the primary screen’s vertical retrace, eliminating flicker.
  • display (Display) – The display device to use. Useful only under X11.
  • screen (Screen) – The screen to use, if in fullscreen.
  • config (pyglet.gl.Config) – Either a template from which to create a complete config, or a complete config.
  • context (pyglet.gl.Context) – The context to attach to this window. The context must not already be attached to another window.
  • mode (ScreenMode) – The screen will be switched to this mode if fullscreen is True. If None, an appropriate mode is selected to accomodate width and height.

Methods:

activate() Attempt to restore keyboard focus to the window.
clear() Clear the window.
close() Close the window.
dispatch_event(*args)
dispatch_events() Poll the operating system event queue for new events and call attached event handlers.
draw_mouse_cursor() Draw the custom mouse cursor.
event(*args) Function decorator for an event handler.
flip() Swap the OpenGL front and back buffers.
get_location() Return the current position of the window.
get_size() Return the current size of the window.
get_system_mouse_cursor(name) Obtain a system mouse cursor.
maximize() Maximize the window.
minimize() Minimize the window.
pop_handlers() Pop the top level of event handlers off the stack.
push_handlers(*args, **kwargs) Push a level onto the top of the handler stack, then attach zero or more event handlers.
register_event_type(name) Register an event type with the dispatcher.
remove_handler(name, handler) Remove a single event handler.
remove_handlers(*args, **kwargs) Remove event handlers from the event stack.
set_caption(caption) Set the window’s caption.
set_exclusive_keyboard([exclusive]) Prevent the user from switching away from this window using keyboard accelerators.
set_exclusive_mouse([exclusive]) Hide the mouse cursor and direct all mouse events to this window.
set_fullscreen([fullscreen, screen, mode, ...]) Toggle to or from fullscreen.
set_handler(name, handler) Attach a single event handler.
set_handlers(*args, **kwargs) Attach one or more event handlers to the top level of the handler stack.
set_icon(*images) Set the window icon.
set_location(x, y) Set the position of the window.
set_maximum_size(width, height) Set the maximum size of the window.
set_minimum_size(width, height) Set the minimum size of the window.
set_mouse_cursor([cursor]) Change the appearance of the mouse cursor.
set_mouse_platform_visible([platform_visible]) Set the platform-drawn mouse cursor visibility.
set_mouse_visible([visible]) Show or hide the mouse cursor.
set_size(width, height) Resize the window.
set_visible([visible]) Show or hide the window.
set_vsync(vsync) Enable or disable vertical sync control.
switch_to() Make this window the current OpenGL rendering context.

Events:

on_activate() The window was activated.
on_close() The user attempted to close the window.
on_context_lost() The window’s GL context was lost.
on_context_state_lost() The state of the window’s GL context was lost.
on_deactivate() The window was deactivated.
on_draw() The window contents must be redrawn.
on_expose() A portion of the window needs to be redrawn.
on_hide() The window was hidden.
on_key_press(symbol, modifiers) A key on the keyboard was pressed (and held down).
on_key_release(symbol, modifiers) A key on the keyboard was released.
on_mouse_drag(x, y, dx, dy, buttons, modifiers) The mouse was moved with one or more mouse buttons pressed.
on_mouse_enter(x, y) The mouse was moved into the window.
on_mouse_leave(x, y) The mouse was moved outside of the window.
on_mouse_motion(x, y, dx, dy) The mouse was moved with no buttons held down.
on_mouse_press(x, y, button, modifiers) A mouse button was pressed (and held down).
on_mouse_release(x, y, button, modifiers) A mouse button was released.
on_mouse_scroll(x, y, scroll_x, scroll_y) The mouse wheel was scrolled.
on_move(x, y) The window was moved.
on_resize(width, height) The window was resized.
on_show() The window was shown.
on_text(text) The user input some text.
on_text_motion(motion) The user moved the text input cursor.
on_text_motion_select(motion) The user moved the text input cursor while extending the selection.

Attributes:

CURSOR_CROSSHAIR Type: str
CURSOR_DEFAULT
CURSOR_HAND Type: str
CURSOR_HELP Type: str
CURSOR_NO Type: str
CURSOR_SIZE Type: str
CURSOR_SIZE_DOWN Type: str
CURSOR_SIZE_DOWN_LEFT Type: str
CURSOR_SIZE_DOWN_RIGHT Type: str
CURSOR_SIZE_LEFT Type: str
CURSOR_SIZE_LEFT_RIGHT Type: str
CURSOR_SIZE_RIGHT Type: str
CURSOR_SIZE_UP Type: str
CURSOR_SIZE_UP_DOWN Type: str
CURSOR_SIZE_UP_LEFT Type: str
CURSOR_SIZE_UP_RIGHT Type: str
CURSOR_TEXT Type: str
CURSOR_WAIT Type: str
CURSOR_WAIT_ARROW Type: str
WINDOW_STYLE_BORDERLESS Type: str
WINDOW_STYLE_DEFAULT
WINDOW_STYLE_DIALOG Type: str
WINDOW_STYLE_TOOL Type: str
caption The window caption (title).
config A GL config describing the context of this window. Read-only.
context The OpenGL context attached to this window. Read-only.
display The display this window belongs to.
event_types Type: list
fullscreen True if the window is currently fullscreen.
has_exit Type: bool
height The height of the window, in pixels.
invalid Type: bool
resizable True if the window is resizable.
screen The screen this window is fullscreen in.
style The window style; one of the WINDOW_STYLE_* constants.
visible True if the window is currently visible.
vsync True if buffer flips are synchronised to the screen’s vertical retrace.
width The width of the window, in pixels.

Methods

Window.activate()

Attempt to restore keyboard focus to the window.

Depending on the window manager or operating system, this may not be successful. For example, on Windows XP an application is not allowed to “steal” focus from another application. Instead, the window’s taskbar icon will flash, indicating it requires attention.

Window.clear()

Clear the window.

This is a convenience method for clearing the color and depth buffer. The window must be the active context (see switch_to).

Window.close()

Close the window.

After closing the window, the GL context will be invalid. The window instance cannot be reused once closed (see also set_visible).

The pyglet.app.EventLoop.on_window_close event is dispatched on pyglet.app.event_loop when this method is called.

Window.dispatch_event(*args)
Window.dispatch_events()

Poll the operating system event queue for new events and call attached event handlers.

This method is provided for legacy applications targeting pyglet 1.0, and advanced applications that must integrate their event loop into another framework.

Typical applications should use pyglet.app.run.

Window.draw_mouse_cursor()

Draw the custom mouse cursor.

If the current mouse cursor has drawable set, this method is called before the buffers are flipped to render it.

This method always leaves the GL_MODELVIEW matrix as current, regardless of what it was set to previously. No other GL state is affected.

There is little need to override this method; instead, subclass MouseCursor and provide your own draw method.

Window.flip()

Swap the OpenGL front and back buffers.

Call this method on a double-buffered window to update the visible display with the back buffer. The contents of the back buffer is undefined after this operation.

Windows are double-buffered by default. This method is called automatically by EventLoop after the on_draw event.

Window.get_location()

Return the current position of the window.

Return type:(int, int)
Returns:The distances of the left and top edges from their respective edges on the virtual desktop, in pixels.
Window.get_size()

Return the current size of the window.

The window size does not include the border or title bar.

Return type:(int, int)
Returns:The width and height of the window, in pixels.
Window.get_system_mouse_cursor(name)

Obtain a system mouse cursor.

Use set_mouse_cursor to make the cursor returned by this method active. The names accepted by this method are the CURSOR_* constants defined on this class.

Parameters:name (str) – Name describing the mouse cursor to return. For example, CURSOR_WAIT, CURSOR_HELP, etc.
Return type:MouseCursor
Returns:A mouse cursor which can be used with set_mouse_cursor.
Window.maximize()

Maximize the window.

The behaviour of this method is somewhat dependent on the user’s display setup. On a multi-monitor system, the window may maximize to either a single screen or the entire virtual desktop.

Window.minimize()

Minimize the window.

Window.set_caption(caption)

Set the window’s caption.

The caption appears in the titlebar of the window, if it has one, and in the taskbar on Windows and many X11 window managers.

Parameters:caption (str or unicode) – The caption to set.
Window.set_exclusive_keyboard(exclusive=True)

Prevent the user from switching away from this window using keyboard accelerators.

When enabled, this feature disables certain operating-system specific key combinations such as Alt+Tab (Command+Tab on OS X). This can be useful in certain kiosk applications, it should be avoided in general applications or games.

Parameters:exclusive (bool) – If True, exclusive keyboard is enabled, otherwise it is disabled.
Window.set_exclusive_mouse(exclusive=True)

Hide the mouse cursor and direct all mouse events to this window.

When enabled, this feature prevents the mouse leaving the window. It is useful for certain styles of games that require complete control of the mouse. The position of the mouse as reported in subsequent events is meaningless when exclusive mouse is enabled; you should only use the relative motion parameters dx and dy.

Parameters:exclusive (bool) – If True, exclusive mouse is enabled, otherwise it is disabled.
Window.set_fullscreen(fullscreen=True, screen=None, mode=None, width=None, height=None)

Toggle to or from fullscreen.

After toggling fullscreen, the GL context should have retained its state and objects, however the buffers will need to be cleared and redrawn.

If width and height are specified and fullscreen is True, the screen may be switched to a different resolution that most closely matches the given size. If the resolution doesn’t match exactly, a higher resolution is selected and the window will be centered within a black border covering the rest of the screen.

Parameters:
  • fullscreen (bool) – True if the window should be made fullscreen, False if it should be windowed.
  • screen (Screen) – If not None and fullscreen is True, the window is moved to the given screen. The screen must belong to the same display as the window.
  • mode (ScreenMode) – The screen will be switched to the given mode. The mode must have been obtained by enumerating Screen.get_modes. If None, an appropriate mode will be selected from the given width and height.
  • width (int) – Optional width of the window. If unspecified, defaults to the previous window size when windowed, or the screen size if fullscreen. Since: pyglet 1.2
  • height (int) – Optional height of the window. If unspecified, defaults to the previous window size when windowed, or the screen size if fullscreen. Since: pyglet 1.2
Window.set_icon(*images)

Set the window icon.

If multiple images are provided, one with an appropriate size will be selected (if the correct size is not provided, the image will be scaled).

Useful sizes to provide are 16x16, 32x32, 64x64 (Mac only) and 128x128 (Mac only).

Parameters:images (sequence of pyglet.image.AbstractImage) – List of images to use for the window icon.
Window.set_location(x, y)

Set the position of the window.

Parameters:
  • x (int) – Distance of the left edge of the window from the left edge of the virtual desktop, in pixels.
  • y (int) – Distance of the top edge of the window from the top edge of the virtual desktop, in pixels.
Window.set_maximum_size(width, height)

Set the maximum size of the window.

Once set, the user will not be able to resize the window larger than the given dimensions. There is no way to remove the maximum size constraint on a window (but you could set it to a large value).

The behaviour is undefined if the maximum size is set smaller than the current size of the window.

The window size does not include the border or title bar.

Parameters:
  • width (int) – Maximum width of the window, in pixels.
  • height (int) – Maximum height of the window, in pixels.
Window.set_minimum_size(width, height)

Set the minimum size of the window.

Once set, the user will not be able to resize the window smaller than the given dimensions. There is no way to remove the minimum size constraint on a window (but you could set it to 0,0).

The behaviour is undefined if the minimum size is set larger than the current size of the window.

The window size does not include the border or title bar.

Parameters:
  • width (int) – Minimum width of the window, in pixels.
  • height (int) – Minimum height of the window, in pixels.
Window.set_mouse_cursor(cursor=None)

Change the appearance of the mouse cursor.

The appearance of the mouse cursor is only changed while it is within this window.

Parameters:cursor (MouseCursor) – The cursor to set, or None to restore the default cursor.
Window.set_mouse_platform_visible(platform_visible=None)

Set the platform-drawn mouse cursor visibility. This is called automatically after changing the mouse cursor or exclusive mode.

Applications should not normally need to call this method, see set_mouse_visible instead.

Parameters:platform_visible (bool or None) – If None, sets platform visibility to the required visibility for the current exclusive mode and cursor type. Otherwise, a bool value will override and force a visibility.
Window.set_mouse_visible(visible=True)

Show or hide the mouse cursor.

The mouse cursor will only be hidden while it is positioned within this window. Mouse events will still be processed as usual.

Parameters:visible (bool) – If True, the mouse cursor will be visible, otherwise it will be hidden.
Window.set_size(width, height)

Resize the window.

The behaviour is undefined if the window is not resizable, or if it is currently fullscreen.

The window size does not include the border or title bar.

Parameters:
  • width (int) – New width of the window, in pixels.
  • height (int) – New height of the window, in pixels.
Window.set_visible(visible=True)

Show or hide the window.

Parameters:visible (bool) – If True, the window will be shown; otherwise it will be hidden.
Window.set_vsync(vsync)

Enable or disable vertical sync control.

When enabled, this option ensures flips from the back to the front buffer are performed only during the vertical retrace period of the primary display. This can prevent “tearing” or flickering when the buffer is updated in the middle of a video scan.

Note that LCD monitors have an analogous time in which they are not reading from the video buffer; while it does not correspond to a vertical retrace it has the same effect.

With multi-monitor systems the secondary monitor cannot be synchronised to, so tearing and flicker cannot be avoided when the window is positioned outside of the primary display. In this case it may be advisable to forcibly reduce the framerate (for example, using pyglet.clock.set_fps_limit).

Parameters:vsync (bool) – If True, vsync is enabled, otherwise it is disabled.
Window.switch_to()

Make this window the current OpenGL rendering context.

Only one OpenGL context can be active at a time. This method sets the current window’s context to be current. You should use this method in preference to pyglet.gl.Context.set_current, as it may perform additional initialisation functions.

Events

Window.on_activate()

The window was activated.

This event can be triggered by clicking on the title bar, bringing it to the foreground; or by some platform-specific method.

When a window is “active” it has the keyboard focus.

Window.on_close()

The user attempted to close the window.

This event can be triggered by clicking on the “X” control box in the window title bar, or by some other platform-dependent manner.

The default handler sets has_exit to True. In pyglet 1.1, if pyglet.app.event_loop is being used, close is also called, closing the window immediately.

Window.on_context_lost()

The window’s GL context was lost.

When the context is lost no more GL methods can be called until it is recreated. This is a rare event, triggered perhaps by the user switching to an incompatible video mode. When it occurs, an application will need to reload all objects (display lists, texture objects, shaders) as well as restore the GL state.

Window.on_context_state_lost()

The state of the window’s GL context was lost.

pyglet may sometimes need to recreate the window’s GL context if the window is moved to another video device, or between fullscreen or windowed mode. In this case it will try to share the objects (display lists, texture objects, shaders) between the old and new contexts. If this is possible, only the current state of the GL context is lost, and the application should simply restore state.

Window.on_deactivate()

The window was deactivated.

This event can be triggered by clicking on another application window. When a window is deactivated it no longer has the keyboard focus.

Window.on_draw()

The window contents must be redrawn.

The EventLoop will dispatch this event when the window should be redrawn. This will happen during idle time after any window events and after any scheduled functions were called.

The window will already have the GL context, so there is no need to call switch_to. The window’s flip method will be called after this event, so your event handler should not.

You should make no assumptions about the window contents when this event is triggered; a resize or expose event may have invalidated the framebuffer since the last time it was drawn.

Note

Since pyglet 1.1

Window.on_expose()

A portion of the window needs to be redrawn.

This event is triggered when the window first appears, and any time the contents of the window is invalidated due to another window obscuring it.

There is no way to determine which portion of the window needs redrawing. Note that the use of this method is becoming increasingly uncommon, as newer window managers composite windows automatically and keep a backing store of the window contents.

Window.on_hide()

The window was hidden.

This event is triggered when a window is minimised or (on Mac OS X) hidden by the user.

Window.on_key_press(symbol, modifiers)

A key on the keyboard was pressed (and held down).

In pyglet 1.0 the default handler sets has_exit to True if the ESC key is pressed.

In pyglet 1.1 the default handler dispatches the on_close event if the ESC key is pressed.

Parameters:
  • symbol (int) – The key symbol pressed.
  • modifiers (int) – Bitwise combination of the key modifiers active.
Window.on_key_release(symbol, modifiers)

A key on the keyboard was released.

Parameters:
  • symbol (int) – The key symbol pressed.
  • modifiers (int) – Bitwise combination of the key modifiers active.
Window.on_mouse_drag(x, y, dx, dy, buttons, modifiers)

The mouse was moved with one or more mouse buttons pressed.

This event will continue to be fired even if the mouse leaves the window, so long as the drag buttons are continuously held down.

Parameters:
  • x (int) – Distance in pixels from the left edge of the window.
  • y (int) – Distance in pixels from the bottom edge of the window.
  • dx (int) – Relative X position from the previous mouse position.
  • dy (int) – Relative Y position from the previous mouse position.
  • buttons (int) – Bitwise combination of the mouse buttons currently pressed.
  • modifiers (int) – Bitwise combination of any keyboard modifiers currently active.
Window.on_mouse_enter(x, y)

The mouse was moved into the window.

This event will not be trigged if the mouse is currently being dragged.

Parameters:
  • x (int) – Distance in pixels from the left edge of the window.
  • y (int) – Distance in pixels from the bottom edge of the window.
Window.on_mouse_leave(x, y)

The mouse was moved outside of the window.

This event will not be trigged if the mouse is currently being dragged. Note that the coordinates of the mouse pointer will be outside of the window rectangle.

Parameters:
  • x (int) – Distance in pixels from the left edge of the window.
  • y (int) – Distance in pixels from the bottom edge of the window.
Window.on_mouse_motion(x, y, dx, dy)

The mouse was moved with no buttons held down.

Parameters:
  • x (int) – Distance in pixels from the left edge of the window.
  • y (int) – Distance in pixels from the bottom edge of the window.
  • dx (int) – Relative X position from the previous mouse position.
  • dy (int) – Relative Y position from the previous mouse position.
Window.on_mouse_press(x, y, button, modifiers)

A mouse button was pressed (and held down).

Parameters:
  • x (int) – Distance in pixels from the left edge of the window.
  • y (int) – Distance in pixels from the bottom edge of the window.
  • button (int) – The mouse button that was pressed.
  • modifiers (int) – Bitwise combination of any keyboard modifiers currently active.
Window.on_mouse_release(x, y, button, modifiers)

A mouse button was released.

Parameters:
  • x (int) – Distance in pixels from the left edge of the window.
  • y (int) – Distance in pixels from the bottom edge of the window.
  • button (int) – The mouse button that was released.
  • modifiers (int) – Bitwise combination of any keyboard modifiers currently active.
Window.on_mouse_scroll(x, y, scroll_x, scroll_y)

The mouse wheel was scrolled.

Note that most mice have only a vertical scroll wheel, so scroll_x is usually 0. An exception to this is the Apple Mighty Mouse, which has a mouse ball in place of the wheel which allows both scroll_x and scroll_y movement.

Parameters:
  • x (int) – Distance in pixels from the left edge of the window.
  • y (int) – Distance in pixels from the bottom edge of the window.
  • scroll_x (int) – Number of “clicks” towards the right (left if negative).
  • scroll_y (int) – Number of “clicks” upwards (downwards if negative).
Window.on_move(x, y)

The window was moved.

Parameters:
  • x (int) – Distance from the left edge of the screen to the left edge of the window.
  • y (int) – Distance from the top edge of the screen to the top edge of the window. Note that this is one of few methods in pyglet which use a Y-down coordinate system.
Window.on_resize(width, height)

The window was resized.

The window will have the GL context when this event is dispatched; there is no need to call switch_to in this handler.

Parameters:
  • width (int) – The new width of the window, in pixels.
  • height (int) – The new height of the window, in pixels.
Window.on_show()

The window was shown.

This event is triggered when a window is restored after being minimised, or after being displayed for the first time.

Window.on_text(text)

The user input some text.

Typically this is called after on_key_press and before on_key_release, but may also be called multiple times if the key is held down (key repeating); or called without key presses if another input method was used (e.g., a pen input).

You should always use this method for interpreting text, as the key symbols often have complex mappings to their unicode representation which this event takes care of.

Parameters:text (unicode) – The text entered by the user.
Window.on_text_motion(motion)

The user moved the text input cursor.

Typically this is called after on_key_press and before on_key_release, but may also be called multiple times if the key is help down (key repeating).

You should always use this method for moving the text input cursor (caret), as different platforms have different default keyboard mappings, and key repeats are handled correctly.

The values that motion can take are defined in pyglet.window.key:

  • MOTION_UP
  • MOTION_RIGHT
  • MOTION_DOWN
  • MOTION_LEFT
  • MOTION_NEXT_WORD
  • MOTION_PREVIOUS_WORD
  • MOTION_BEGINNING_OF_LINE
  • MOTION_END_OF_LINE
  • MOTION_NEXT_PAGE
  • MOTION_PREVIOUS_PAGE
  • MOTION_BEGINNING_OF_FILE
  • MOTION_END_OF_FILE
  • MOTION_BACKSPACE
  • MOTION_DELETE
Parameters:motion (int) – The direction of motion; see remarks.
Window.on_text_motion_select(motion)

The user moved the text input cursor while extending the selection.

Typically this is called after on_key_press and before on_key_release, but may also be called multiple times if the key is help down (key repeating).

You should always use this method for responding to text selection events rather than the raw on_key_press, as different platforms have different default keyboard mappings, and key repeats are handled correctly.

The values that motion can take are defined in pyglet.window.key:

  • MOTION_UP
  • MOTION_RIGHT
  • MOTION_DOWN
  • MOTION_LEFT
  • MOTION_NEXT_WORD
  • MOTION_PREVIOUS_WORD
  • MOTION_BEGINNING_OF_LINE
  • MOTION_END_OF_LINE
  • MOTION_NEXT_PAGE
  • MOTION_PREVIOUS_PAGE
  • MOTION_BEGINNING_OF_FILE
  • MOTION_END_OF_FILE
Parameters:motion (int) – The direction of selection motion; see remarks.

Attributes

Window.CURSOR_CROSSHAIR = 'crosshair'
Window.CURSOR_DEFAULT = None
Window.CURSOR_HAND = 'hand'
Window.CURSOR_HELP = 'help'
Window.CURSOR_NO = 'no'
Window.CURSOR_SIZE = 'size'
Window.CURSOR_SIZE_DOWN = 'size_down'
Window.CURSOR_SIZE_DOWN_LEFT = 'size_down_left'
Window.CURSOR_SIZE_DOWN_RIGHT = 'size_down_right'
Window.CURSOR_SIZE_LEFT = 'size_left'
Window.CURSOR_SIZE_LEFT_RIGHT = 'size_left_right'
Window.CURSOR_SIZE_RIGHT = 'size_right'
Window.CURSOR_SIZE_UP = 'size_up'
Window.CURSOR_SIZE_UP_DOWN = 'size_up_down'
Window.CURSOR_SIZE_UP_LEFT = 'size_up_left'
Window.CURSOR_SIZE_UP_RIGHT = 'size_up_right'
Window.CURSOR_TEXT = 'text'
Window.CURSOR_WAIT = 'wait'
Window.CURSOR_WAIT_ARROW = 'wait_arrow'
Window.WINDOW_STYLE_BORDERLESS = 'borderless'
Window.WINDOW_STYLE_DEFAULT = None
Window.WINDOW_STYLE_DIALOG = 'dialog'
Window.WINDOW_STYLE_TOOL = 'tool'
Window.caption

The window caption (title). Read-only.

Type:str
Window.config

A GL config describing the context of this window. Read-only.

Type:pyglet.gl.Config
Window.context

The OpenGL context attached to this window. Read-only.

Type:pyglet.gl.Context
Window.display

The display this window belongs to. Read-only.

Type:Display
Window.event_types = ['on_key_press', 'on_key_release', 'on_text', 'on_text_motion', 'on_text_motion_select', 'on_mouse_motion', 'on_mouse_drag', 'on_mouse_press', 'on_mouse_release', 'on_mouse_scroll', 'on_mouse_enter', 'on_mouse_leave', 'on_close', 'on_expose', 'on_resize', 'on_move', 'on_activate', 'on_deactivate', 'on_show', 'on_hide', 'on_context_lost', 'on_context_state_lost', 'on_draw']
Window.fullscreen

True if the window is currently fullscreen. Read-only.

Type:bool
Window.has_exit = False
Window.height

The height of the window, in pixels. Read-write.

Type:int
Window.invalid = True
Window.resizable

True if the window is resizable. Read-only.

Type:bool
Window.screen

The screen this window is fullscreen in. Read-only.

Type:Screen
Window.style

The window style; one of the WINDOW_STYLE_* constants. Read-only.

Type:int
Window.visible

True if the window is currently visible. Read-only.

Type:bool
Window.vsync

True if buffer flips are synchronised to the screen’s vertical retrace. Read-only.

Type:bool
Window.width

The width of the window, in pixels. Read-write.

Type:int

Inherited members

Methods

Window.event(*args)

Function decorator for an event handler.

Usage:

win = window.Window()

@win.event
def on_resize(self, width, height):
    # ...

or:

@win.event('on_resize')
def foo(self, width, height):
    # ...
Window.pop_handlers()

Pop the top level of event handlers off the stack.

Window.push_handlers(*args, **kwargs)

Push a level onto the top of the handler stack, then attach zero or more event handlers.

If keyword arguments are given, they name the event type to attach. Otherwise, a callable’s __name__ attribute will be used. Any other object may also be specified, in which case it will be searched for callables with event names.

classmethod Window.register_event_type(name)

Register an event type with the dispatcher.

Registering event types allows the dispatcher to validate event handler names as they are attached, and to search attached objects for suitable handlers.

Parameters:name (str) – Name of the event to register.
Window.remove_handler(name, handler)

Remove a single event handler.

The given event handler is removed from the first handler stack frame it appears in. The handler must be the exact same callable as passed to set_handler, set_handlers or push_handlers; and the name must match the event type it is bound to.

No error is raised if the event handler is not set.

Parameters:
  • name (str) – Name of the event type to remove.
  • handler (callable) – Event handler to remove.
Window.remove_handlers(*args, **kwargs)

Remove event handlers from the event stack.

See push_handlers for the accepted argument types. All handlers are removed from the first stack frame that contains any of the given handlers. No error is raised if any handler does not appear in that frame, or if no stack frame contains any of the given handlers.

If the stack frame is empty after removing the handlers, it is removed from the stack. Note that this interferes with the expected symmetry of push_handlers and pop_handlers.

Window.set_handler(name, handler)

Attach a single event handler.

Parameters:
  • name (str) – Name of the event type to attach to.
  • handler (callable) – Event handler to attach.
Window.set_handlers(*args, **kwargs)

Attach one or more event handlers to the top level of the handler stack.

See push_handlers for the accepted argument types.

Table Of Contents

Previous topic

Platform Class

Next topic

MouseCursorException