Window Backends
pyglet
- class moderngl_window.context.pyglet.window.Window(**kwargs: Any)[source]
Bases:
BaseWindowWindow based on Pyglet 1.4.x
- property aspect_ratio: float
The current aspect ratio of the window. If a fixed aspect ratio was passed to the window initializer this value will always be returned. Otherwise
width / heightwill be returned.This property is read only.
- Type:
float
- property backend: str | None
Name of the context backend.
This is
Noneunless a backend is explicitly specified during context creation. The main use case for this is to enable EGL in headless mode.
- property buffer_height: int
the current window buffer height
- Type:
int
- property buffer_size: tuple[int, int]
tuple with the current window buffer size
- Type:
tuple[int, int]
- property buffer_width: int
the current window buffer width
- Type:
int
- clear(red: float = 0.0, green: float = 0.0, blue: float = 0.0, alpha: float = 0.0, depth: float = 1.0, viewport: tuple[int, int, int, int] | None = None) None
Binds and clears the default framebuffer
- Parameters:
red (float) – color component
green (float) – color component
blue (float) – color component
alpha (float) – alpha component
depth (float) – depth value
viewport (tuple) – The viewport
- property close_func: Callable[[], None]
Get or set the close callable
- Type:
callable
- property config: WindowConfig | None
Get or det the current WindowConfig instance
Assigning a WindowConfig instance will automatically set up the necessary event callback methods:
window.config = window_config_instance
- convert_window_coordinates(x: int, y: int, x_flipped: bool = False, y_flipped: bool = False) tuple[int, int]
Convert window coordinates to top-left coordinate space. The default origin is the top left corner of the window.
If you are converting from bottom origin coordinates use x_flipped=True
If you are converting from right origin coordinates use y_flipped=True
- Parameters:
x_flipped (bool)
y_flipped (bool)
- Returns:
tuple (x, y) of converted window coordinates
- property ctx: Context
The ModernGL context for the window
- Type:
moderngl.Context
- property cursor: bool
Should the mouse cursor be visible inside the window?
This property can also be assigned to:
# Disable cursor window.cursor = False
- Type:
bool
- property exit_key: Any
Get or set the exit/close key for the window.
Pressing this key will close the window.
By default the
ESCAPEis set, but this can be overridden or disabled:# Default exit key window.exit_key = window.keys.ESCAPE # Set some other random exit key window.exit_key = window.keys.Q # Disable the exit key window.exit_key = None
- property fbo: Framebuffer
The default framebuffer
- Type:
moderngl.Framebuffer
- property files_dropped_event_func: Callable[[int, int, list[str | Path]], None]
Get or set the files_dropped callable
- Type:
callable
- property fixed_aspect_ratio: float | None
The fixed aspect ratio for the window.
Can be set to
Noneto disable fixed aspect ratio making the aspect ratio adjust to the actual window sizeThis will affects how the viewport is calculated and the reported value from the
aspect_ratioproperty:# Enabled fixed aspect ratio window.fixed_aspect_ratio = 16 / 9 # Disable fixed aspect ratio window.fixed_aspect_ratio = None
- Type:
float
- property frames: int
Number of frames rendered
- Type:
int
- property fullscreen: bool
Window is in fullscreen mode
- Type:
bool
- property fullscreen_key: Any
Get or set the fullscreen toggle key for the window.
Pressing this key will toggle fullscreen for the window.
By default this is set to
F11, but this can be overridden or disabled:# Default fullscreen key window.fullscreen_key = window.keys.F11 # Set some other random fullscreen key window.fullscreen_key = window.keys.F # Disable the fullscreen key window.fullscreen_key = None
- property gl_version: tuple[int, int]
(major, minor) required OpenGL version
- Type:
tuple[int, int]
- property gl_version_code: int
Generates the version code integer for the selected OpenGL version.
gl_version (4, 1) returns 410
- Type:
int
- property headless: bool
Is the window headless?
- Type:
bool
- property height: int
The current window height
- Type:
int
Window is hidden
- Type:
bool
- hide() None
Hide the window
- property iconify_func: Callable[[bool], None]
Get or set ehe iconify/show/hide callable
- Type:
callable
- init_mgl_context() None
Create or assign a ModernGL context. If no context is supplied a context will be created using the window’s
gl_version.- Keyword Arguments:
ctx – An optional custom ModernGL context
- property is_closing: bool
Check pyglet’s internal exit state
- is_key_pressed(key: str) bool
Returns: The press state of a key
- property key_event_func: Callable[[str | int, int, KeyModifiers], None]
Get or set the key_event callable
- Type:
callable
- keys
Pyglet specific key constants
alias of
Keys
- property modifiers: KeyModifiers
(KeyModifiers) The current keyboard modifiers
- mouse
alias of
MouseButtons
- property mouse_drag_event_func: Callable[[int, int, int, int], None]
Get or set the mouse_drag callable
- Type:
callable
- property mouse_exclusivity: bool
If mouse exclusivity is enabled.
When you enable mouse-exclusive mode, the mouse cursor is no longer available. It is not merely hidden – no amount of mouse movement will make it leave your application. This is for example useful when you don’t want the mouse leaving the screen when rotating a 3d scene.
This property can also be set:
window.mouse_exclusivity = True
- Type:
bool
- property mouse_position_event_func: Callable[[int, int, int, int], None]
Get or set the mouse_position callable
- Type:
callable
- property mouse_press_event_func: Callable[[int, int, int], None]
Get or set the mouse_press callable
- Type:
callable
- property mouse_release_event_func: Callable[[int, int, int], None]
Get or set the mouse_release callable
- Type:
callable
- property mouse_scroll_event_func: Callable[[float, float], None]
Get or set the mouse_scroll_event calable
- Type:
callable
- property mouse_states: MouseButtonStates
Mouse button state structure.
The current mouse button states.
window.mouse_buttons.left window.mouse_buttons.right window.mouse_buttons.middle
- Type:
MouseButtonStates
- name = 'pyglet'
Name of the window
- on_file_drop(x: int, y: int, paths: list[str | Path]) None[source]
Called when files dropped onto the window
- Parameters:
x (int) – X location in window where file was dropped
y (int) – Y location in window where file was dropped
paths (list) – List of file paths dropped
- property on_generic_event_func: Callable[[int, int, int, int], None] | None
Get or set the on_generic_event callable used to funnel all non-processed events
- Type:
callable
- on_key_press(symbol: int, modifiers: int) bool[source]
Pyglet specific key press callback.
Forwards and translates the events to the standard methods.
- Parameters:
symbol – The symbol of the pressed key
modifiers – Modifier state (shift, ctrl etc.)
- on_key_release(symbol: int, modifiers: int) None[source]
Pyglet specific key release callback.
Forwards and translates the events to standard methods.
- Parameters:
symbol – The symbol of the pressed key
modifiers – Modifier state (shift, ctrl etc.)
- on_mouse_drag(x: int, y: int, dx: int, dy: int, buttons: int, modifiers: int) None[source]
Pyglet specific mouse drag event.
When a mouse button is pressed this is the only way to capture mouse position events
- on_mouse_motion(x: int, y: int, dx: int, dy: int) None[source]
Pyglet specific mouse motion callback.
Forwards and translates the event to the standard methods.
- Parameters:
x – x position of the mouse
y – y position of the mouse
dx – delta x position
dy – delta y position of the mouse
- on_mouse_press(x: int, y: int, button: int, mods: int) None[source]
Handle mouse press events and forward to standard methods
- Parameters:
x – x position of the mouse when pressed
y – y position of the mouse when pressed
button – The pressed button
mods – Modifiers
- on_mouse_release(x: int, y: int, button: int, mods: int) None[source]
Handle mouse release events and forward to standard methods
- Parameters:
x – x position when mouse button was released
y – y position when mouse button was released
button – The button pressed
mods – Modifiers
- on_mouse_scroll(x: int, y: int, x_offset: float, y_offset: float) None[source]
Handle mouse wheel.
- Parameters:
x_offset (float) – X scroll offset
y_offset (float) – Y scroll offset
- on_resize(width: int, height: int) None[source]
Pyglet specific callback for window resize events forwarding to standard methods
- Parameters:
width – New window width
height – New window height
- on_text(text: str) None[source]
Pyglet specific text input callback
Forwards and translates the events to the standard methods.
- Parameters:
text (str) – The unicode character entered
- property pixel_ratio: float
The framebuffer/window size ratio
- Type:
float
- property position: tuple[int, int]
The current window position.
This property can also be set to move the window:
# Move window to 100, 100 window.position = 100, 100
- Type:
tuple[int, int]
- print_context_info() None
Prints moderngl context info.
- render(time: float = 0.0, frame_time: float = 0.0) None
Renders a frame by calling the configured render callback
- Keyword Arguments:
time (float) – Current time in seconds
frame_time (float) – Delta time from last frame in seconds
- property render_func: Callable[[float, float], None]
The render callable
This property can also be used to assign a callable.
- Type:
callable
- property resizable: bool
Window is resizable
- Type:
bool
- resize(width: int, height: int) None
Should be called every time window is resized so the example can adapt to the new size if needed
- property resize_func: Callable[[int, int], None]
Get or set the resize callable
- Type:
callable
- property samples: int
Number of Multisample anti-aliasing (MSAA) samples
- Type:
float
- set_default_viewport() None
Calculates the and sets the viewport based on window configuration.
The viewport will based on the configured fixed aspect ratio if set. If no fixed aspect ratio is set the viewport will be scaled to the entire window size regardless of size.
Will add black borders and center the viewport if the window do not match the configured viewport (fixed only)
- set_icon(icon_path: str) None
Sets the window icon to the given path
- Parameters:
icon_path (str) – path to the icon
- show() None
Show the window
- property size: tuple[int, int]
current window size.
This property also support assignment:
# Resize the window to 1000 x 1000 window.size = 1000, 1000
- Type:
tuple[int, int]
- property title: str
Window title.
This property can also be set:
window.title = "New Title"
- Type:
str
- property unicode_char_entered_func: Callable[[str], None]
Get or set the unicode_char_entered callable
- Type:
callable
- use() None
Bind the window’s framebuffer
- property viewport: tuple[int, int, int, int]
current window viewport
- Type:
tuple[int, int, int, int]
- property viewport_height: int
The height of the viewport
Equivalent to
self.viewport[3].- Type:
int
- property viewport_size: tuple[int, int]
Size of the viewport.
Equivalent to
self.viewport[2], self.viewport[3]- Type:
tuple[int,int]
- property viewport_width: int
The width of the viewport.
Equivalent to
self.viewport[2].- Type:
int
- property visible: bool
Is the window visible?
This property can also be set:
# Hide or show the window window.visible = False
- Type:
bool
- property vsync: bool
vertical sync enabled/disabled
- Type:
bool
- property width: int
The current window width
- Type:
int
glfw
- class moderngl_window.context.glfw.window.Window(**kwargs: Any)[source]
Bases:
BaseWindowWindow based on GLFW
- property aspect_ratio: float
The current aspect ratio of the window. If a fixed aspect ratio was passed to the window initializer this value will always be returned. Otherwise
width / heightwill be returned.This property is read only.
- Type:
float
- property backend: str | None
Name of the context backend.
This is
Noneunless a backend is explicitly specified during context creation. The main use case for this is to enable EGL in headless mode.
- property buffer_height: int
the current window buffer height
- Type:
int
- property buffer_size: tuple[int, int]
tuple with the current window buffer size
- Type:
tuple[int, int]
- property buffer_width: int
the current window buffer width
- Type:
int
- clear(red: float = 0.0, green: float = 0.0, blue: float = 0.0, alpha: float = 0.0, depth: float = 1.0, viewport: tuple[int, int, int, int] | None = None) None
Binds and clears the default framebuffer
- Parameters:
red (float) – color component
green (float) – color component
blue (float) – color component
alpha (float) – alpha component
depth (float) – depth value
viewport (tuple) – The viewport
- property close_func: Callable[[], None]
Get or set the close callable
- Type:
callable
- property config: WindowConfig | None
Get or det the current WindowConfig instance
Assigning a WindowConfig instance will automatically set up the necessary event callback methods:
window.config = window_config_instance
- convert_window_coordinates(x: int, y: int, x_flipped: bool = False, y_flipped: bool = False) tuple[int, int]
Convert window coordinates to top-left coordinate space. The default origin is the top left corner of the window.
If you are converting from bottom origin coordinates use x_flipped=True
If you are converting from right origin coordinates use y_flipped=True
- Parameters:
x_flipped (bool)
y_flipped (bool)
- Returns:
tuple (x, y) of converted window coordinates
- property ctx: Context
The ModernGL context for the window
- Type:
moderngl.Context
- property cursor: bool
Should the mouse cursor be visible inside the window?
This property can also be assigned to:
# Disable cursor window.cursor = False
- Type:
bool
- property exit_key: Any
Get or set the exit/close key for the window.
Pressing this key will close the window.
By default the
ESCAPEis set, but this can be overridden or disabled:# Default exit key window.exit_key = window.keys.ESCAPE # Set some other random exit key window.exit_key = window.keys.Q # Disable the exit key window.exit_key = None
- property fbo: Framebuffer
The default framebuffer
- Type:
moderngl.Framebuffer
- property files_dropped_event_func: Callable[[int, int, list[str | Path]], None]
Get or set the files_dropped callable
- Type:
callable
- property fixed_aspect_ratio: float | None
The fixed aspect ratio for the window.
Can be set to
Noneto disable fixed aspect ratio making the aspect ratio adjust to the actual window sizeThis will affects how the viewport is calculated and the reported value from the
aspect_ratioproperty:# Enabled fixed aspect ratio window.fixed_aspect_ratio = 16 / 9 # Disable fixed aspect ratio window.fixed_aspect_ratio = None
- Type:
float
- property frames: int
Number of frames rendered
- Type:
int
- property fullscreen: bool
Window is in fullscreen mode
- Type:
bool
- property fullscreen_key: Any
Get or set the fullscreen toggle key for the window.
Pressing this key will toggle fullscreen for the window.
By default this is set to
F11, but this can be overridden or disabled:# Default fullscreen key window.fullscreen_key = window.keys.F11 # Set some other random fullscreen key window.fullscreen_key = window.keys.F # Disable the fullscreen key window.fullscreen_key = None
- property gl_version: tuple[int, int]
(major, minor) required OpenGL version
- Type:
tuple[int, int]
- property gl_version_code: int
Generates the version code integer for the selected OpenGL version.
gl_version (4, 1) returns 410
- Type:
int
- glfw_char_callback(window: Any, codepoint: int) None[source]
Handle text input (only unicode charaters)
- Parameters:
window – The glfw window
codepoint (int) – The unicode codepoint
- glfw_cursor_enter(window: Any, enter: int) None[source]
called when the cursor enters or leaves the content area of the window.
- Parameters:
window – the window instance
enter (int) – 0: leave, 1: enter
- glfw_key_event_callback(window: Any, key: int, scancode: int, action: int, mods: int) None[source]
Key event callback for glfw. Translates and forwards keyboard event to
keyboard_event()- Parameters:
window – Window event origin
key – The key that was pressed or released.
scancode – The system-specific scancode of the key.
action –
GLFW_PRESS,GLFW_RELEASEorGLFW_REPEATmods – Bit field describing which modifier keys were held down.
- glfw_mouse_button_callback(window: Any, button: int, action: int, mods: int) None[source]
Handle mouse button events and forward them to the example
- Parameters:
window – The window
button – The button creating the event
action – Button action (press or release)
mods – They modifiers such as ctrl or shift
- glfw_mouse_event_callback(window: Any, xpos: float, ypos: float) None[source]
Mouse position event callback from glfw. Translates the events forwarding them to
cursor_event().Screen coordinates relative to the top-left corner
- Parameters:
window – The window
xpos – viewport x pos
ypos – viewport y pos
- glfw_mouse_scroll_callback(window: Any, x_offset: float, y_offset: float) None[source]
Handle mouse scroll events and forward them to the example
- Parameters:
window – The window
x_offset (float) – x wheel offset
y_offest (float) – y wheel offset
- glfw_window_focus(window: Any, focused: int) None[source]
Called when the window focus is changed.
- Parameters:
window – The window instance
focused (int) – 0: de-focus, 1: focused
- glfw_window_iconify(window: Any, iconified: int) None[source]
Called when the window is minimized or restored.
- Parameters:
window – The window
iconified (int) – 1 = minimized, 0 = restored.
- glfw_window_resize_callback(window: Any, width: int, height: int) None[source]
Window resize callback for glfw
- Parameters:
window – The window
width – New width
height – New height
- property headless: bool
Is the window headless?
- Type:
bool
- property height: int
The current window height
- Type:
int
Window is hidden
- Type:
bool
- hide() None
Hide the window
- property iconify_func: Callable[[bool], None]
Get or set ehe iconify/show/hide callable
- Type:
callable
- init_mgl_context() None
Create or assign a ModernGL context. If no context is supplied a context will be created using the window’s
gl_version.- Keyword Arguments:
ctx – An optional custom ModernGL context
- property is_closing: bool
Checks if the window is scheduled for closing
- Type:
bool
- is_key_pressed(key: str) bool
Returns: The press state of a key
- property key_event_func: Callable[[str | int, int, KeyModifiers], None]
Get or set the key_event callable
- Type:
callable
- keys
GLFW specific key constants
alias of
Keys
- property modifiers: KeyModifiers
(KeyModifiers) The current keyboard modifiers
- mouse
alias of
MouseButtons
- property mouse_drag_event_func: Callable[[int, int, int, int], None]
Get or set the mouse_drag callable
- Type:
callable
- property mouse_exclusivity: bool
If mouse exclusivity is enabled.
When you enable mouse-exclusive mode, the mouse cursor is no longer available. It is not merely hidden – no amount of mouse movement will make it leave your application. This is for example useful when you don’t want the mouse leaving the screen when rotating a 3d scene.
This property can also be set:
window.mouse_exclusivity = True
- Type:
bool
- property mouse_position_event_func: Callable[[int, int, int, int], None]
Get or set the mouse_position callable
- Type:
callable
- property mouse_press_event_func: Callable[[int, int, int], None]
Get or set the mouse_press callable
- Type:
callable
- property mouse_release_event_func: Callable[[int, int, int], None]
Get or set the mouse_release callable
- Type:
callable
- property mouse_scroll_event_func: Callable[[float, float], None]
Get or set the mouse_scroll_event calable
- Type:
callable
- property mouse_states: MouseButtonStates
Mouse button state structure.
The current mouse button states.
window.mouse_buttons.left window.mouse_buttons.right window.mouse_buttons.middle
- Type:
MouseButtonStates
- name = 'glfw'
Name of the window
- property on_generic_event_func: Callable[[int, int, int, int], None] | None
Get or set the on_generic_event callable used to funnel all non-processed events
- Type:
callable
- property pixel_ratio: float
The framebuffer/window size ratio
- Type:
float
- property position: tuple[int, int]
The current window position.
This property can also be set to move the window:
# Move window to 100, 100 window.position = 100, 100
- Type:
tuple[int, int]
- print_context_info() None
Prints moderngl context info.
- render(time: float = 0.0, frame_time: float = 0.0) None
Renders a frame by calling the configured render callback
- Keyword Arguments:
time (float) – Current time in seconds
frame_time (float) – Delta time from last frame in seconds
- property render_func: Callable[[float, float], None]
The render callable
This property can also be used to assign a callable.
- Type:
callable
- property resizable: bool
Window is resizable
- Type:
bool
- resize(width: int, height: int) None
Should be called every time window is resized so the example can adapt to the new size if needed
- property resize_func: Callable[[int, int], None]
Get or set the resize callable
- Type:
callable
- property samples: int
Number of Multisample anti-aliasing (MSAA) samples
- Type:
float
- set_default_viewport() None
Calculates the and sets the viewport based on window configuration.
The viewport will based on the configured fixed aspect ratio if set. If no fixed aspect ratio is set the viewport will be scaled to the entire window size regardless of size.
Will add black borders and center the viewport if the window do not match the configured viewport (fixed only)
- set_icon(icon_path: str) None
Sets the window icon to the given path
- Parameters:
icon_path (str) – path to the icon
- show() None
Show the window
- property size: tuple[int, int]
current window size.
This property also support assignment:
# Resize the window to 1000 x 1000 window.size = 1000, 1000
- Type:
tuple[int, int]
- property title: str
Window title.
This property can also be set:
window.title = "New Title"
- Type:
str
- property unicode_char_entered_func: Callable[[str], None]
Get or set the unicode_char_entered callable
- Type:
callable
- use() None
Bind the window’s framebuffer
- property viewport: tuple[int, int, int, int]
current window viewport
- Type:
tuple[int, int, int, int]
- property viewport_height: int
The height of the viewport
Equivalent to
self.viewport[3].- Type:
int
- property viewport_size: tuple[int, int]
Size of the viewport.
Equivalent to
self.viewport[2], self.viewport[3]- Type:
tuple[int,int]
- property viewport_width: int
The width of the viewport.
Equivalent to
self.viewport[2].- Type:
int
- property visible: bool
Is the window visible?
This property can also be set:
# Hide or show the window window.visible = False
- Type:
bool
- property vsync: bool
vertical sync enabled/disabled
- Type:
bool
- property width: int
The current window width
- Type:
int
sdl2
- class moderngl_window.context.sdl2.window.Window(**kwargs: Any)[source]
Bases:
BaseWindowBasic window implementation using SDL2.
- property aspect_ratio: float
The current aspect ratio of the window. If a fixed aspect ratio was passed to the window initializer this value will always be returned. Otherwise
width / heightwill be returned.This property is read only.
- Type:
float
- property backend: str | None
Name of the context backend.
This is
Noneunless a backend is explicitly specified during context creation. The main use case for this is to enable EGL in headless mode.
- property buffer_height: int
the current window buffer height
- Type:
int
- property buffer_size: tuple[int, int]
tuple with the current window buffer size
- Type:
tuple[int, int]
- property buffer_width: int
the current window buffer width
- Type:
int
- clear(red: float = 0.0, green: float = 0.0, blue: float = 0.0, alpha: float = 0.0, depth: float = 1.0, viewport: tuple[int, int, int, int] | None = None) None
Binds and clears the default framebuffer
- Parameters:
red (float) – color component
green (float) – color component
blue (float) – color component
alpha (float) – alpha component
depth (float) – depth value
viewport (tuple) – The viewport
- property close_func: Callable[[], None]
Get or set the close callable
- Type:
callable
- property config: WindowConfig | None
Get or det the current WindowConfig instance
Assigning a WindowConfig instance will automatically set up the necessary event callback methods:
window.config = window_config_instance
- convert_window_coordinates(x: int, y: int, x_flipped: bool = False, y_flipped: bool = False) tuple[int, int]
Convert window coordinates to top-left coordinate space. The default origin is the top left corner of the window.
If you are converting from bottom origin coordinates use x_flipped=True
If you are converting from right origin coordinates use y_flipped=True
- Parameters:
x_flipped (bool)
y_flipped (bool)
- Returns:
tuple (x, y) of converted window coordinates
- property ctx: Context
The ModernGL context for the window
- Type:
moderngl.Context
- property cursor: bool
Should the mouse cursor be visible inside the window?
This property can also be assigned to:
# Disable cursor window.cursor = False
- Type:
bool
- property exit_key: Any
Get or set the exit/close key for the window.
Pressing this key will close the window.
By default the
ESCAPEis set, but this can be overridden or disabled:# Default exit key window.exit_key = window.keys.ESCAPE # Set some other random exit key window.exit_key = window.keys.Q # Disable the exit key window.exit_key = None
- property fbo: Framebuffer
The default framebuffer
- Type:
moderngl.Framebuffer
- property files_dropped_event_func: Callable[[int, int, list[str | Path]], None]
Get or set the files_dropped callable
- Type:
callable
- property fixed_aspect_ratio: float | None
The fixed aspect ratio for the window.
Can be set to
Noneto disable fixed aspect ratio making the aspect ratio adjust to the actual window sizeThis will affects how the viewport is calculated and the reported value from the
aspect_ratioproperty:# Enabled fixed aspect ratio window.fixed_aspect_ratio = 16 / 9 # Disable fixed aspect ratio window.fixed_aspect_ratio = None
- Type:
float
- property frames: int
Number of frames rendered
- Type:
int
- property fullscreen: bool
Window is in fullscreen mode
- Type:
bool
- property fullscreen_key: Any
Get or set the fullscreen toggle key for the window.
Pressing this key will toggle fullscreen for the window.
By default this is set to
F11, but this can be overridden or disabled:# Default fullscreen key window.fullscreen_key = window.keys.F11 # Set some other random fullscreen key window.fullscreen_key = window.keys.F # Disable the fullscreen key window.fullscreen_key = None
- property gl_version: tuple[int, int]
(major, minor) required OpenGL version
- Type:
tuple[int, int]
- property gl_version_code: int
Generates the version code integer for the selected OpenGL version.
gl_version (4, 1) returns 410
- Type:
int
- property headless: bool
Is the window headless?
- Type:
bool
- property height: int
The current window height
- Type:
int
Window is hidden
- Type:
bool
- hide() None
Hide the window
- property iconify_func: Callable[[bool], None]
Get or set ehe iconify/show/hide callable
- Type:
callable
- init_mgl_context() None
Create or assign a ModernGL context. If no context is supplied a context will be created using the window’s
gl_version.- Keyword Arguments:
ctx – An optional custom ModernGL context
- property is_closing: bool
Is the window about to close?
- Type:
bool
- is_key_pressed(key: str) bool
Returns: The press state of a key
- property key_event_func: Callable[[str | int, int, KeyModifiers], None]
Get or set the key_event callable
- Type:
callable
- keys
SDL2 specific key constants
alias of
Keys
- property modifiers: KeyModifiers
(KeyModifiers) The current keyboard modifiers
- mouse
alias of
MouseButtons
- property mouse_drag_event_func: Callable[[int, int, int, int], None]
Get or set the mouse_drag callable
- Type:
callable
- property mouse_exclusivity: bool
If mouse exclusivity is enabled.
When you enable mouse-exclusive mode, the mouse cursor is no longer available. It is not merely hidden – no amount of mouse movement will make it leave your application. This is for example useful when you don’t want the mouse leaving the screen when rotating a 3d scene.
This property can also be set:
window.mouse_exclusivity = True
- Type:
bool
- property mouse_position_event_func: Callable[[int, int, int, int], None]
Get or set the mouse_position callable
- Type:
callable
- property mouse_press_event_func: Callable[[int, int, int], None]
Get or set the mouse_press callable
- Type:
callable
- property mouse_release_event_func: Callable[[int, int, int], None]
Get or set the mouse_release callable
- Type:
callable
- property mouse_scroll_event_func: Callable[[float, float], None]
Get or set the mouse_scroll_event calable
- Type:
callable
- property mouse_states: MouseButtonStates
Mouse button state structure.
The current mouse button states.
window.mouse_buttons.left window.mouse_buttons.right window.mouse_buttons.middle
- Type:
MouseButtonStates
- name = 'sdl2'
Name of the window
- property on_generic_event_func: Callable[[int, int, int, int], None] | None
Get or set the on_generic_event callable used to funnel all non-processed events
- Type:
callable
- property pixel_ratio: float
The framebuffer/window size ratio
- Type:
float
- property position: tuple[int, int]
The current window position.
This property can also be set to move the window:
# Move window to 100, 100 window.position = 100, 100
- Type:
tuple[int, int]
- print_context_info() None
Prints moderngl context info.
- process_events() None[source]
Handle all queued events in sdl2 dispatching events to standard methods
- render(time: float = 0.0, frame_time: float = 0.0) None
Renders a frame by calling the configured render callback
- Keyword Arguments:
time (float) – Current time in seconds
frame_time (float) – Delta time from last frame in seconds
- property render_func: Callable[[float, float], None]
The render callable
This property can also be used to assign a callable.
- Type:
callable
- property resizable: bool
Window is resizable
- Type:
bool
- resize(width: int, height: int) None[source]
Resize callback.
- Parameters:
width – New window width
height – New window height
- property resize_func: Callable[[int, int], None]
Get or set the resize callable
- Type:
callable
- property samples: int
Number of Multisample anti-aliasing (MSAA) samples
- Type:
float
- set_default_viewport() None
Calculates the and sets the viewport based on window configuration.
The viewport will based on the configured fixed aspect ratio if set. If no fixed aspect ratio is set the viewport will be scaled to the entire window size regardless of size.
Will add black borders and center the viewport if the window do not match the configured viewport (fixed only)
- set_icon(icon_path: str) None
Sets the window icon to the given path
- Parameters:
icon_path (str) – path to the icon
- show() None
Show the window
- property size: tuple[int, int]
current window size.
This property also support assignment:
# Resize the window to 1000 x 1000 window.size = 1000, 1000
- Type:
tuple[int, int]
- property title: str
Window title.
This property can also be set:
window.title = "New Title"
- Type:
str
- property unicode_char_entered_func: Callable[[str], None]
Get or set the unicode_char_entered callable
- Type:
callable
- use() None
Bind the window’s framebuffer
- property viewport: tuple[int, int, int, int]
current window viewport
- Type:
tuple[int, int, int, int]
- property viewport_height: int
The height of the viewport
Equivalent to
self.viewport[3].- Type:
int
- property viewport_size: tuple[int, int]
Size of the viewport.
Equivalent to
self.viewport[2], self.viewport[3]- Type:
tuple[int,int]
- property viewport_width: int
The width of the viewport.
Equivalent to
self.viewport[2].- Type:
int
- property visible: bool
Is the window visible?
This property can also be set:
# Hide or show the window window.visible = False
- Type:
bool
- property vsync: bool
vertical sync enabled/disabled
- Type:
bool
- property width: int
The current window width
- Type:
int
pygame
- class moderngl_window.context.pygame2.window.Window(**kwargs: Any)[source]
Bases:
BaseWindowBasic window implementation using pygame2.
- property aspect_ratio: float
The current aspect ratio of the window. If a fixed aspect ratio was passed to the window initializer this value will always be returned. Otherwise
width / heightwill be returned.This property is read only.
- Type:
float
- property backend: str | None
Name of the context backend.
This is
Noneunless a backend is explicitly specified during context creation. The main use case for this is to enable EGL in headless mode.
- property buffer_height: int
the current window buffer height
- Type:
int
- property buffer_size: tuple[int, int]
tuple with the current window buffer size
- Type:
tuple[int, int]
- property buffer_width: int
the current window buffer width
- Type:
int
- clear(red: float = 0.0, green: float = 0.0, blue: float = 0.0, alpha: float = 0.0, depth: float = 1.0, viewport: tuple[int, int, int, int] | None = None) None
Binds and clears the default framebuffer
- Parameters:
red (float) – color component
green (float) – color component
blue (float) – color component
alpha (float) – alpha component
depth (float) – depth value
viewport (tuple) – The viewport
- property close_func: Callable[[], None]
Get or set the close callable
- Type:
callable
- property config: WindowConfig | None
Get or det the current WindowConfig instance
Assigning a WindowConfig instance will automatically set up the necessary event callback methods:
window.config = window_config_instance
- convert_window_coordinates(x: int, y: int, x_flipped: bool = False, y_flipped: bool = False) tuple[int, int]
Convert window coordinates to top-left coordinate space. The default origin is the top left corner of the window.
If you are converting from bottom origin coordinates use x_flipped=True
If you are converting from right origin coordinates use y_flipped=True
- Parameters:
x_flipped (bool)
y_flipped (bool)
- Returns:
tuple (x, y) of converted window coordinates
- property ctx: Context
The ModernGL context for the window
- Type:
moderngl.Context
- property cursor: bool
Should the mouse cursor be visible inside the window?
This property can also be assigned to:
# Disable cursor window.cursor = False
- Type:
bool
- property exit_key: Any
Get or set the exit/close key for the window.
Pressing this key will close the window.
By default the
ESCAPEis set, but this can be overridden or disabled:# Default exit key window.exit_key = window.keys.ESCAPE # Set some other random exit key window.exit_key = window.keys.Q # Disable the exit key window.exit_key = None
- property fbo: Framebuffer
The default framebuffer
- Type:
moderngl.Framebuffer
- property files_dropped_event_func: Callable[[int, int, list[str | Path]], None]
Get or set the files_dropped callable
- Type:
callable
- property fixed_aspect_ratio: float | None
The fixed aspect ratio for the window.
Can be set to
Noneto disable fixed aspect ratio making the aspect ratio adjust to the actual window sizeThis will affects how the viewport is calculated and the reported value from the
aspect_ratioproperty:# Enabled fixed aspect ratio window.fixed_aspect_ratio = 16 / 9 # Disable fixed aspect ratio window.fixed_aspect_ratio = None
- Type:
float
- property frames: int
Number of frames rendered
- Type:
int
- property fullscreen: bool
Window is in fullscreen mode
- Type:
bool
- property fullscreen_key: Any
Get or set the fullscreen toggle key for the window.
Pressing this key will toggle fullscreen for the window.
By default this is set to
F11, but this can be overridden or disabled:# Default fullscreen key window.fullscreen_key = window.keys.F11 # Set some other random fullscreen key window.fullscreen_key = window.keys.F # Disable the fullscreen key window.fullscreen_key = None
- property gl_version: tuple[int, int]
(major, minor) required OpenGL version
- Type:
tuple[int, int]
- property gl_version_code: int
Generates the version code integer for the selected OpenGL version.
gl_version (4, 1) returns 410
- Type:
int
- property headless: bool
Is the window headless?
- Type:
bool
- property height: int
The current window height
- Type:
int
Window is hidden
- Type:
bool
- hide() None
Hide the window
- property iconify_func: Callable[[bool], None]
Get or set ehe iconify/show/hide callable
- Type:
callable
- init_mgl_context() None
Create or assign a ModernGL context. If no context is supplied a context will be created using the window’s
gl_version.- Keyword Arguments:
ctx – An optional custom ModernGL context
- property is_closing: bool
Is the window about to close?
- Type:
bool
- is_key_pressed(key: str) bool
Returns: The press state of a key
- property key_event_func: Callable[[str | int, int, KeyModifiers], None]
Get or set the key_event callable
- Type:
callable
- keys
pygame specific key constants
alias of
Keys
- property modifiers: KeyModifiers
(KeyModifiers) The current keyboard modifiers
- mouse
alias of
MouseButtons
- property mouse_drag_event_func: Callable[[int, int, int, int], None]
Get or set the mouse_drag callable
- Type:
callable
- property mouse_exclusivity: bool
If mouse exclusivity is enabled.
When you enable mouse-exclusive mode, the mouse cursor is no longer available. It is not merely hidden – no amount of mouse movement will make it leave your application. This is for example useful when you don’t want the mouse leaving the screen when rotating a 3d scene.
This property can also be set:
window.mouse_exclusivity = True
- Type:
bool
- property mouse_position_event_func: Callable[[int, int, int, int], None]
Get or set the mouse_position callable
- Type:
callable
- property mouse_press_event_func: Callable[[int, int, int], None]
Get or set the mouse_press callable
- Type:
callable
- property mouse_release_event_func: Callable[[int, int, int], None]
Get or set the mouse_release callable
- Type:
callable
- property mouse_scroll_event_func: Callable[[float, float], None]
Get or set the mouse_scroll_event calable
- Type:
callable
- property mouse_states: MouseButtonStates
Mouse button state structure.
The current mouse button states.
window.mouse_buttons.left window.mouse_buttons.right window.mouse_buttons.middle
- Type:
MouseButtonStates
- name = 'pygame2'
Name of the window
- property on_generic_event_func: Callable[[int, int, int, int], None] | None
Get or set the on_generic_event callable used to funnel all non-processed events
- Type:
callable
- property pixel_ratio: float
The framebuffer/window size ratio
- Type:
float
- property position: tuple[int, int]
The current window position.
This property can also be set to move the window:
# Move window to 100, 100 window.position = 100, 100
- Type:
tuple[int, int]
- print_context_info() None
Prints moderngl context info.
- process_events() None[source]
Handle all queued events in pygame2 dispatching events to standard methods
- render(time: float = 0.0, frame_time: float = 0.0) None
Renders a frame by calling the configured render callback
- Keyword Arguments:
time (float) – Current time in seconds
frame_time (float) – Delta time from last frame in seconds
- property render_func: Callable[[float, float], None]
The render callable
This property can also be used to assign a callable.
- Type:
callable
- property resizable: bool
Window is resizable
- Type:
bool
- resize(width: int, height: int) None[source]
Resize callback
- Parameters:
width – New window width
height – New window height
- property resize_func: Callable[[int, int], None]
Get or set the resize callable
- Type:
callable
- property samples: int
Number of Multisample anti-aliasing (MSAA) samples
- Type:
float
- set_default_viewport() None
Calculates the and sets the viewport based on window configuration.
The viewport will based on the configured fixed aspect ratio if set. If no fixed aspect ratio is set the viewport will be scaled to the entire window size regardless of size.
Will add black borders and center the viewport if the window do not match the configured viewport (fixed only)
- set_icon(icon_path: str) None
Sets the window icon to the given path
- Parameters:
icon_path (str) – path to the icon
- show() None
Show the window
- property size: tuple[int, int]
current window size.
This property also support assignment:
# Resize the window to 1000 x 1000 window.size = 1000, 1000
- Type:
tuple[int, int]
- property title: str
Window title.
This property can also be set:
window.title = "New Title"
- Type:
str
- property unicode_char_entered_func: Callable[[str], None]
Get or set the unicode_char_entered callable
- Type:
callable
- use() None
Bind the window’s framebuffer
- property viewport: tuple[int, int, int, int]
current window viewport
- Type:
tuple[int, int, int, int]
- property viewport_height: int
The height of the viewport
Equivalent to
self.viewport[3].- Type:
int
- property viewport_size: tuple[int, int]
Size of the viewport.
Equivalent to
self.viewport[2], self.viewport[3]- Type:
tuple[int,int]
- property viewport_width: int
The width of the viewport.
Equivalent to
self.viewport[2].- Type:
int
- property visible: bool
Is the window visible?
This property can also be set:
# Hide or show the window window.visible = False
- Type:
bool
- property vsync: bool
vertical sync enabled/disabled
- Type:
bool
- property width: int
The current window width
- Type:
int
Pyside2
- class moderngl_window.context.pyside2.window.Window(**kwargs: Any)[source]
Bases:
BaseWindowA basic window implementation using PySide2 with the goal of creating an OpenGL context and handle keyboard and mouse input.
This window bypasses Qt’s own event loop to make things as flexible as possible.
If you need to use the event loop and are using other features in Qt as well, this example can still be useful as a reference when creating your own window.
- property aspect_ratio: float
The current aspect ratio of the window. If a fixed aspect ratio was passed to the window initializer this value will always be returned. Otherwise
width / heightwill be returned.This property is read only.
- Type:
float
- property backend: str | None
Name of the context backend.
This is
Noneunless a backend is explicitly specified during context creation. The main use case for this is to enable EGL in headless mode.
- property buffer_height: int
the current window buffer height
- Type:
int
- property buffer_size: tuple[int, int]
tuple with the current window buffer size
- Type:
tuple[int, int]
- property buffer_width: int
the current window buffer width
- Type:
int
- clear(red: float = 0.0, green: float = 0.0, blue: float = 0.0, alpha: float = 0.0, depth: float = 1.0, viewport: tuple[int, int, int, int] | None = None) None
Binds and clears the default framebuffer
- Parameters:
red (float) – color component
green (float) – color component
blue (float) – color component
alpha (float) – alpha component
depth (float) – depth value
viewport (tuple) – The viewport
- close_event(event: <MagicMock name='mock.QEvent' id='124507139614976'>) None[source]
The standard PyQt close events
- Parameters:
event – The qtevent instance
- property close_func: Callable[[], None]
Get or set the close callable
- Type:
callable
- property config: WindowConfig | None
Get or det the current WindowConfig instance
Assigning a WindowConfig instance will automatically set up the necessary event callback methods:
window.config = window_config_instance
- convert_window_coordinates(x: int, y: int, x_flipped: bool = False, y_flipped: bool = False) tuple[int, int]
Convert window coordinates to top-left coordinate space. The default origin is the top left corner of the window.
If you are converting from bottom origin coordinates use x_flipped=True
If you are converting from right origin coordinates use y_flipped=True
- Parameters:
x_flipped (bool)
y_flipped (bool)
- Returns:
tuple (x, y) of converted window coordinates
- property ctx: Context
The ModernGL context for the window
- Type:
moderngl.Context
- property cursor: bool
Should the mouse cursor be visible inside the window?
This property can also be assigned to:
# Disable cursor window.cursor = False
- Type:
bool
- property exit_key: Any
Get or set the exit/close key for the window.
Pressing this key will close the window.
By default the
ESCAPEis set, but this can be overridden or disabled:# Default exit key window.exit_key = window.keys.ESCAPE # Set some other random exit key window.exit_key = window.keys.Q # Disable the exit key window.exit_key = None
- property fbo: Framebuffer
The default framebuffer
- Type:
moderngl.Framebuffer
- property files_dropped_event_func: Callable[[int, int, list[str | Path]], None]
Get or set the files_dropped callable
- Type:
callable
- property fixed_aspect_ratio: float | None
The fixed aspect ratio for the window.
Can be set to
Noneto disable fixed aspect ratio making the aspect ratio adjust to the actual window sizeThis will affects how the viewport is calculated and the reported value from the
aspect_ratioproperty:# Enabled fixed aspect ratio window.fixed_aspect_ratio = 16 / 9 # Disable fixed aspect ratio window.fixed_aspect_ratio = None
- Type:
float
- property frames: int
Number of frames rendered
- Type:
int
- property fullscreen: bool
Window is in fullscreen mode
- Type:
bool
- property fullscreen_key: Any
Get or set the fullscreen toggle key for the window.
Pressing this key will toggle fullscreen for the window.
By default this is set to
F11, but this can be overridden or disabled:# Default fullscreen key window.fullscreen_key = window.keys.F11 # Set some other random fullscreen key window.fullscreen_key = window.keys.F # Disable the fullscreen key window.fullscreen_key = None
- property gl_version: tuple[int, int]
(major, minor) required OpenGL version
- Type:
tuple[int, int]
- property gl_version_code: int
Generates the version code integer for the selected OpenGL version.
gl_version (4, 1) returns 410
- Type:
int
- property headless: bool
Is the window headless?
- Type:
bool
- property height: int
The current window height
- Type:
int
Window is hidden
- Type:
bool
- hide() None
Hide the window
- hide_event(event: <MagicMock name='mock.QEvent' id='124507139614976'>) None[source]
The standard Qt hide event
- property iconify_func: Callable[[bool], None]
Get or set ehe iconify/show/hide callable
- Type:
callable
- init_mgl_context() None
Create or assign a ModernGL context. If no context is supplied a context will be created using the window’s
gl_version.- Keyword Arguments:
ctx – An optional custom ModernGL context
- property is_closing: bool
Is the window about to close?
- Type:
bool
- is_key_pressed(key: str) bool
Returns: The press state of a key
- property key_event_func: Callable[[str | int, int, KeyModifiers], None]
Get or set the key_event callable
- Type:
callable
- key_pressed_event(event: <MagicMock name='mock.QEvent' id='124507139614976'>) None[source]
Process Qt key press events forwarding them to standard methods
- Parameters:
event – The qtevent instance
- key_release_event(event: <MagicMock name='mock.QEvent' id='124507139614976'>) None[source]
Process Qt key release events forwarding them to standard methods
- Parameters:
event – The qtevent instance
- keys
PySide2 specific key constants
alias of
Keys
- property modifiers: KeyModifiers
(KeyModifiers) The current keyboard modifiers
- mouse
alias of
MouseButtons
- property mouse_drag_event_func: Callable[[int, int, int, int], None]
Get or set the mouse_drag callable
- Type:
callable
- property mouse_exclusivity: bool
If mouse exclusivity is enabled.
When you enable mouse-exclusive mode, the mouse cursor is no longer available. It is not merely hidden – no amount of mouse movement will make it leave your application. This is for example useful when you don’t want the mouse leaving the screen when rotating a 3d scene.
This property can also be set:
window.mouse_exclusivity = True
- Type:
bool
- mouse_move_event(event: <MagicMock name='mock.QEvent' id='124507139614976'>) None[source]
Forward mouse cursor position events to standard methods
- Parameters:
event – The qtevent instance
- property mouse_position_event_func: Callable[[int, int, int, int], None]
Get or set the mouse_position callable
- Type:
callable
- mouse_press_event(event: <MagicMock name='mock.QEvent' id='124507139614976'>) None[source]
Forward mouse press events to standard methods
- Parameters:
event – The qtevent instance
- property mouse_press_event_func: Callable[[int, int, int], None]
Get or set the mouse_press callable
- Type:
callable
- mouse_release_event(event: <MagicMock name='mock.QEvent' id='124507139614976'>) None[source]
Forward mouse release events to standard methods
- Parameters:
event – The qtevent instance
- property mouse_release_event_func: Callable[[int, int, int], None]
Get or set the mouse_release callable
- Type:
callable
- property mouse_scroll_event_func: Callable[[float, float], None]
Get or set the mouse_scroll_event calable
- Type:
callable
- property mouse_states: MouseButtonStates
Mouse button state structure.
The current mouse button states.
window.mouse_buttons.left window.mouse_buttons.right window.mouse_buttons.middle
- Type:
MouseButtonStates
- mouse_wheel_event(event: <MagicMock name='mock.QEvent' id='124507139614976'>) None[source]
Forward mouse wheel events to standard metods.
From Qt docs:
Returns the distance that the wheel is rotated, in eighths of a degree. A positive value indicates that the wheel was rotated forwards away from the user; a negative value indicates that the wheel was rotated backwards toward the user.
Most mouse types work in steps of 15 degrees, in which case the delta value is a multiple of 120; i.e., 120 units * 1/8 = 15 degrees.
However, some mice have finer-resolution wheels and send delta values that are less than 120 units (less than 15 degrees). To support this possibility, you can either cumulatively add the delta values from events until the value of 120 is reached, then scroll the widget, or you can partially scroll the widget in response to each wheel event.
- Parameters:
event (QWheelEvent) – Mouse wheel event
- name = 'pyside2'
Name of the window
- property on_generic_event_func: Callable[[int, int, int, int], None] | None
Get or set the on_generic_event callable used to funnel all non-processed events
- Type:
callable
- property pixel_ratio: float
The framebuffer/window size ratio
- Type:
float
- property position: tuple[int, int]
The current window position.
This property can also be set to move the window:
# Move window to 100, 100 window.position = 100, 100
- Type:
tuple[int, int]
- print_context_info() None
Prints moderngl context info.
- render(time: float = 0.0, frame_time: float = 0.0) None
Renders a frame by calling the configured render callback
- Keyword Arguments:
time (float) – Current time in seconds
frame_time (float) – Delta time from last frame in seconds
- property render_func: Callable[[float, float], None]
The render callable
This property can also be used to assign a callable.
- Type:
callable
- property resizable: bool
Window is resizable
- Type:
bool
- resize(width: int, height: int) None[source]
Replacement for Qt’s
resizeGLmethod.- Parameters:
width – New window width
height – New window height
- property resize_func: Callable[[int, int], None]
Get or set the resize callable
- Type:
callable
- property samples: int
Number of Multisample anti-aliasing (MSAA) samples
- Type:
float
- set_default_viewport() None
Calculates the and sets the viewport based on window configuration.
The viewport will based on the configured fixed aspect ratio if set. If no fixed aspect ratio is set the viewport will be scaled to the entire window size regardless of size.
Will add black borders and center the viewport if the window do not match the configured viewport (fixed only)
- set_icon(icon_path: str) None
Sets the window icon to the given path
- Parameters:
icon_path (str) – path to the icon
- show() None
Show the window
- show_event(event: <MagicMock name='mock.QEvent' id='124507139614976'>) None[source]
The standard Qt show event
- property size: tuple[int, int]
current window size.
This property also support assignment:
# Resize the window to 1000 x 1000 window.size = 1000, 1000
- Type:
tuple[int, int]
- property title: str
Window title.
This property can also be set:
window.title = "New Title"
- Type:
str
- property unicode_char_entered_func: Callable[[str], None]
Get or set the unicode_char_entered callable
- Type:
callable
- use() None
Bind the window’s framebuffer
- property viewport: tuple[int, int, int, int]
current window viewport
- Type:
tuple[int, int, int, int]
- property viewport_height: int
The height of the viewport
Equivalent to
self.viewport[3].- Type:
int
- property viewport_size: tuple[int, int]
Size of the viewport.
Equivalent to
self.viewport[2], self.viewport[3]- Type:
tuple[int,int]
- property viewport_width: int
The width of the viewport.
Equivalent to
self.viewport[2].- Type:
int
- property visible: bool
Is the window visible?
This property can also be set:
# Hide or show the window window.visible = False
- Type:
bool
- property vsync: bool
vertical sync enabled/disabled
- Type:
bool
- property width: int
The current window width
- Type:
int
PyQt5
- class moderngl_window.context.pyqt5.window.Window(**kwargs: Any)[source]
Bases:
BaseWindowA basic window implementation using PyQt5 with the goal of creating an OpenGL context and handle keyboard and mouse input.
This window bypasses Qt’s own event loop to make things as flexible as possible.
If you need to use the event loop and are using other features in Qt as well, this example can still be useful as a reference when creating your own window.
- property aspect_ratio: float
The current aspect ratio of the window. If a fixed aspect ratio was passed to the window initializer this value will always be returned. Otherwise
width / heightwill be returned.This property is read only.
- Type:
float
- property backend: str | None
Name of the context backend.
This is
Noneunless a backend is explicitly specified during context creation. The main use case for this is to enable EGL in headless mode.
- property buffer_height: int
the current window buffer height
- Type:
int
- property buffer_size: tuple[int, int]
tuple with the current window buffer size
- Type:
tuple[int, int]
- property buffer_width: int
the current window buffer width
- Type:
int
- clear(red: float = 0.0, green: float = 0.0, blue: float = 0.0, alpha: float = 0.0, depth: float = 1.0, viewport: tuple[int, int, int, int] | None = None) None
Binds and clears the default framebuffer
- Parameters:
red (float) – color component
green (float) – color component
blue (float) – color component
alpha (float) – alpha component
depth (float) – depth value
viewport (tuple) – The viewport
- close_event(event: <MagicMock name='mock.QEvent' id='124507136449168'>) None[source]
The standard PyQt close events
- Parameters:
event – The qtevent instance
- property close_func: Callable[[], None]
Get or set the close callable
- Type:
callable
- property config: WindowConfig | None
Get or det the current WindowConfig instance
Assigning a WindowConfig instance will automatically set up the necessary event callback methods:
window.config = window_config_instance
- convert_window_coordinates(x: int, y: int, x_flipped: bool = False, y_flipped: bool = False) tuple[int, int]
Convert window coordinates to top-left coordinate space. The default origin is the top left corner of the window.
If you are converting from bottom origin coordinates use x_flipped=True
If you are converting from right origin coordinates use y_flipped=True
- Parameters:
x_flipped (bool)
y_flipped (bool)
- Returns:
tuple (x, y) of converted window coordinates
- property ctx: Context
The ModernGL context for the window
- Type:
moderngl.Context
- property cursor: bool
Should the mouse cursor be visible inside the window?
This property can also be assigned to:
# Disable cursor window.cursor = False
- Type:
bool
- property exit_key: Any
Get or set the exit/close key for the window.
Pressing this key will close the window.
By default the
ESCAPEis set, but this can be overridden or disabled:# Default exit key window.exit_key = window.keys.ESCAPE # Set some other random exit key window.exit_key = window.keys.Q # Disable the exit key window.exit_key = None
- property fbo: Framebuffer
The default framebuffer
- Type:
moderngl.Framebuffer
- property files_dropped_event_func: Callable[[int, int, list[str | Path]], None]
Get or set the files_dropped callable
- Type:
callable
- property fixed_aspect_ratio: float | None
The fixed aspect ratio for the window.
Can be set to
Noneto disable fixed aspect ratio making the aspect ratio adjust to the actual window sizeThis will affects how the viewport is calculated and the reported value from the
aspect_ratioproperty:# Enabled fixed aspect ratio window.fixed_aspect_ratio = 16 / 9 # Disable fixed aspect ratio window.fixed_aspect_ratio = None
- Type:
float
- property frames: int
Number of frames rendered
- Type:
int
- property fullscreen: bool
Window is in fullscreen mode
- Type:
bool
- property fullscreen_key: Any
Get or set the fullscreen toggle key for the window.
Pressing this key will toggle fullscreen for the window.
By default this is set to
F11, but this can be overridden or disabled:# Default fullscreen key window.fullscreen_key = window.keys.F11 # Set some other random fullscreen key window.fullscreen_key = window.keys.F # Disable the fullscreen key window.fullscreen_key = None
- property gl_version: tuple[int, int]
(major, minor) required OpenGL version
- Type:
tuple[int, int]
- property gl_version_code: int
Generates the version code integer for the selected OpenGL version.
gl_version (4, 1) returns 410
- Type:
int
- property headless: bool
Is the window headless?
- Type:
bool
- property height: int
The current window height
- Type:
int
Window is hidden
- Type:
bool
- hide() None
Hide the window
- hide_event(event: <MagicMock name='mock.QEvent' id='124507136449168'>) None[source]
The standard Qt hide event
- property iconify_func: Callable[[bool], None]
Get or set ehe iconify/show/hide callable
- Type:
callable
- init_mgl_context() None
Create or assign a ModernGL context. If no context is supplied a context will be created using the window’s
gl_version.- Keyword Arguments:
ctx – An optional custom ModernGL context
- property is_closing: bool
Is the window about to close?
- Type:
bool
- is_key_pressed(key: str) bool
Returns: The press state of a key
- property key_event_func: Callable[[str | int, int, KeyModifiers], None]
Get or set the key_event callable
- Type:
callable
- key_pressed_event(event: <MagicMock name='mock.QEvent' id='124507136449168'>) None[source]
Process Qt key press events forwarding them to standard methods
- Parameters:
event – The qtevent instance
- key_release_event(event: <MagicMock name='mock.QEvent' id='124507136449168'>) None[source]
Process Qt key release events forwarding them to standard methods
- Parameters:
event – The qtevent instance
- keys
PyQt5 specific key constants
alias of
Keys
- property modifiers: KeyModifiers
(KeyModifiers) The current keyboard modifiers
- mouse
alias of
MouseButtons
- property mouse_drag_event_func: Callable[[int, int, int, int], None]
Get or set the mouse_drag callable
- Type:
callable
- property mouse_exclusivity: bool
If mouse exclusivity is enabled.
When you enable mouse-exclusive mode, the mouse cursor is no longer available. It is not merely hidden – no amount of mouse movement will make it leave your application. This is for example useful when you don’t want the mouse leaving the screen when rotating a 3d scene.
This property can also be set:
window.mouse_exclusivity = True
- Type:
bool
- mouse_move_event(event: <MagicMock name='mock.QEvent' id='124507136449168'>) None[source]
Forward mouse cursor position events to standard methods
- Parameters:
event – The qtevent instance
- property mouse_position_event_func: Callable[[int, int, int, int], None]
Get or set the mouse_position callable
- Type:
callable
- mouse_press_event(event: <MagicMock name='mock.QEvent' id='124507136449168'>) None[source]
Forward mouse press events to standard methods
- Parameters:
event – The qtevent instance
- property mouse_press_event_func: Callable[[int, int, int], None]
Get or set the mouse_press callable
- Type:
callable
- mouse_release_event(event: <MagicMock name='mock.QEvent' id='124507136449168'>) None[source]
Forward mouse release events to standard methods
- Parameters:
event – The qtevent instance
- property mouse_release_event_func: Callable[[int, int, int], None]
Get or set the mouse_release callable
- Type:
callable
- property mouse_scroll_event_func: Callable[[float, float], None]
Get or set the mouse_scroll_event calable
- Type:
callable
- property mouse_states: MouseButtonStates
Mouse button state structure.
The current mouse button states.
window.mouse_buttons.left window.mouse_buttons.right window.mouse_buttons.middle
- Type:
MouseButtonStates
- mouse_wheel_event(event: <MagicMock name='mock.QEvent' id='124507136449168'>) None[source]
Forward mouse wheel events to standard metods.
From Qt docs:
Returns the distance that the wheel is rotated, in eighths of a degree. A positive value indicates that the wheel was rotated forwards away from the user; a negative value indicates that the wheel was rotated backwards toward the user.
Most mouse types work in steps of 15 degrees, in which case the delta value is a multiple of 120; i.e., 120 units * 1/8 = 15 degrees.
However, some mice have finer-resolution wheels and send delta values that are less than 120 units (less than 15 degrees). To support this possibility, you can either cumulatively add the delta values from events until the value of 120 is reached, then scroll the widget, or you can partially scroll the widget in response to each wheel event.
- Parameters:
event (QWheelEvent) – Mouse wheel event
- name = 'pyqt5'
Name of the window
- property on_generic_event_func: Callable[[int, int, int, int], None] | None
Get or set the on_generic_event callable used to funnel all non-processed events
- Type:
callable
- property pixel_ratio: float
The framebuffer/window size ratio
- Type:
float
- property position: tuple[int, int]
The current window position.
This property can also be set to move the window:
# Move window to 100, 100 window.position = 100, 100
- Type:
tuple[int, int]
- print_context_info() None
Prints moderngl context info.
- render(time: float = 0.0, frame_time: float = 0.0) None
Renders a frame by calling the configured render callback
- Keyword Arguments:
time (float) – Current time in seconds
frame_time (float) – Delta time from last frame in seconds
- property render_func: Callable[[float, float], None]
The render callable
This property can also be used to assign a callable.
- Type:
callable
- property resizable: bool
Window is resizable
- Type:
bool
- resize(width: int, height: int) None[source]
Replacement for Qt’s
resizeGLmethod.- Parameters:
width – New window width
height – New window height
- property resize_func: Callable[[int, int], None]
Get or set the resize callable
- Type:
callable
- property samples: int
Number of Multisample anti-aliasing (MSAA) samples
- Type:
float
- set_default_viewport() None
Calculates the and sets the viewport based on window configuration.
The viewport will based on the configured fixed aspect ratio if set. If no fixed aspect ratio is set the viewport will be scaled to the entire window size regardless of size.
Will add black borders and center the viewport if the window do not match the configured viewport (fixed only)
- set_icon(icon_path: str) None
Sets the window icon to the given path
- Parameters:
icon_path (str) – path to the icon
- show() None
Show the window
- show_event(event: <MagicMock name='mock.QEvent' id='124507136449168'>) None[source]
The standard Qt show event
- property size: tuple[int, int]
current window size.
This property also support assignment:
# Resize the window to 1000 x 1000 window.size = 1000, 1000
- Type:
tuple[int, int]
- property title: str
Window title.
This property can also be set:
window.title = "New Title"
- Type:
str
- property unicode_char_entered_func: Callable[[str], None]
Get or set the unicode_char_entered callable
- Type:
callable
- use() None
Bind the window’s framebuffer
- property viewport: tuple[int, int, int, int]
current window viewport
- Type:
tuple[int, int, int, int]
- property viewport_height: int
The height of the viewport
Equivalent to
self.viewport[3].- Type:
int
- property viewport_size: tuple[int, int]
Size of the viewport.
Equivalent to
self.viewport[2], self.viewport[3]- Type:
tuple[int,int]
- property viewport_width: int
The width of the viewport.
Equivalent to
self.viewport[2].- Type:
int
- property visible: bool
Is the window visible?
This property can also be set:
# Hide or show the window window.visible = False
- Type:
bool
- property vsync: bool
vertical sync enabled/disabled
- Type:
bool
- property width: int
The current window width
- Type:
int
tkinter
headless
- class moderngl_window.context.headless.window.Window(**kwargs: Any)[source]
Bases:
BaseWindowHeadless window.
Do not currently support any form window events or key input.
- property aspect_ratio: float
The current aspect ratio of the window. If a fixed aspect ratio was passed to the window initializer this value will always be returned. Otherwise
width / heightwill be returned.This property is read only.
- Type:
float
- property backend: str | None
Name of the context backend.
This is
Noneunless a backend is explicitly specified during context creation. The main use case for this is to enable EGL in headless mode.
- property buffer_height: int
the current window buffer height
- Type:
int
- property buffer_size: tuple[int, int]
tuple with the current window buffer size
- Type:
tuple[int, int]
- property buffer_width: int
the current window buffer width
- Type:
int
- clear(red: float = 0.0, green: float = 0.0, blue: float = 0.0, alpha: float = 0.0, depth: float = 1.0, viewport: tuple[int, int, int, int] | None = None) None[source]
Binds and clears the default framebuffer
- Parameters:
red (float) – color component
green (float) – color component
blue (float) – color component
alpha (float) – alpha component
depth (float) – depth value
viewport (tuple) – The viewport
- close() None
Signal for the window to close
- property close_func: Callable[[], None]
Get or set the close callable
- Type:
callable
- property config: WindowConfig | None
Get or det the current WindowConfig instance
Assigning a WindowConfig instance will automatically set up the necessary event callback methods:
window.config = window_config_instance
- convert_window_coordinates(x: int, y: int, x_flipped: bool = False, y_flipped: bool = False) tuple[int, int]
Convert window coordinates to top-left coordinate space. The default origin is the top left corner of the window.
If you are converting from bottom origin coordinates use x_flipped=True
If you are converting from right origin coordinates use y_flipped=True
- Parameters:
x_flipped (bool)
y_flipped (bool)
- Returns:
tuple (x, y) of converted window coordinates
- property ctx: Context
The ModernGL context for the window
- Type:
moderngl.Context
- property cursor: bool
Should the mouse cursor be visible inside the window?
This property can also be assigned to:
# Disable cursor window.cursor = False
- Type:
bool
- property exit_key: Any
Get or set the exit/close key for the window.
Pressing this key will close the window.
By default the
ESCAPEis set, but this can be overridden or disabled:# Default exit key window.exit_key = window.keys.ESCAPE # Set some other random exit key window.exit_key = window.keys.Q # Disable the exit key window.exit_key = None
- property fbo: Framebuffer
The default framebuffer
- Type:
moderngl.Framebuffer
- property files_dropped_event_func: Callable[[int, int, list[str | Path]], None]
Get or set the files_dropped callable
- Type:
callable
- property fixed_aspect_ratio: float | None
The fixed aspect ratio for the window.
Can be set to
Noneto disable fixed aspect ratio making the aspect ratio adjust to the actual window sizeThis will affects how the viewport is calculated and the reported value from the
aspect_ratioproperty:# Enabled fixed aspect ratio window.fixed_aspect_ratio = 16 / 9 # Disable fixed aspect ratio window.fixed_aspect_ratio = None
- Type:
float
- property frames: int
Number of frames rendered
- Type:
int
- property fullscreen: bool
Window is in fullscreen mode
- Type:
bool
- property fullscreen_key: Any
Get or set the fullscreen toggle key for the window.
Pressing this key will toggle fullscreen for the window.
By default this is set to
F11, but this can be overridden or disabled:# Default fullscreen key window.fullscreen_key = window.keys.F11 # Set some other random fullscreen key window.fullscreen_key = window.keys.F # Disable the fullscreen key window.fullscreen_key = None
- property gl_version: tuple[int, int]
(major, minor) required OpenGL version
- Type:
tuple[int, int]
- property gl_version_code: int
Generates the version code integer for the selected OpenGL version.
gl_version (4, 1) returns 410
- Type:
int
- property headless: bool
Is the window headless?
- Type:
bool
- property height: int
The current window height
- Type:
int
Window is hidden
- Type:
bool
- hide() None
Hide the window
- property iconify_func: Callable[[bool], None]
Get or set ehe iconify/show/hide callable
- Type:
callable
- property is_closing: bool
Is the window about to close?
- Type:
bool
- is_key_pressed(key: str) bool
Returns: The press state of a key
- property key_event_func: Callable[[str | int, int, KeyModifiers], None]
Get or set the key_event callable
- Type:
callable
- keys
alias of
Keys
- property modifiers: KeyModifiers
(KeyModifiers) The current keyboard modifiers
- mouse
alias of
MouseButtons
- property mouse_drag_event_func: Callable[[int, int, int, int], None]
Get or set the mouse_drag callable
- Type:
callable
- property mouse_exclusivity: bool
If mouse exclusivity is enabled.
When you enable mouse-exclusive mode, the mouse cursor is no longer available. It is not merely hidden – no amount of mouse movement will make it leave your application. This is for example useful when you don’t want the mouse leaving the screen when rotating a 3d scene.
This property can also be set:
window.mouse_exclusivity = True
- Type:
bool
- property mouse_position_event_func: Callable[[int, int, int, int], None]
Get or set the mouse_position callable
- Type:
callable
- property mouse_press_event_func: Callable[[int, int, int], None]
Get or set the mouse_press callable
- Type:
callable
- property mouse_release_event_func: Callable[[int, int, int], None]
Get or set the mouse_release callable
- Type:
callable
- property mouse_scroll_event_func: Callable[[float, float], None]
Get or set the mouse_scroll_event calable
- Type:
callable
- property mouse_states: MouseButtonStates
Mouse button state structure.
The current mouse button states.
window.mouse_buttons.left window.mouse_buttons.right window.mouse_buttons.middle
- Type:
MouseButtonStates
- name = 'headless'
Name of the window
- property on_generic_event_func: Callable[[int, int, int, int], None] | None
Get or set the on_generic_event callable used to funnel all non-processed events
- Type:
callable
- property pixel_ratio: float
The framebuffer/window size ratio
- Type:
float
- property position: tuple[int, int]
The current window position.
This property can also be set to move the window:
# Move window to 100, 100 window.position = 100, 100
- Type:
tuple[int, int]
- print_context_info() None
Prints moderngl context info.
- render(time: float = 0.0, frame_time: float = 0.0) None
Renders a frame by calling the configured render callback
- Keyword Arguments:
time (float) – Current time in seconds
frame_time (float) – Delta time from last frame in seconds
- property render_func: Callable[[float, float], None]
The render callable
This property can also be used to assign a callable.
- Type:
callable
- property resizable: bool
Window is resizable
- Type:
bool
- resize(width: int, height: int) None
Should be called every time window is resized so the example can adapt to the new size if needed
- property resize_func: Callable[[int, int], None]
Get or set the resize callable
- Type:
callable
- property samples: int
Number of Multisample anti-aliasing (MSAA) samples
- Type:
float
- set_default_viewport() None
Calculates the and sets the viewport based on window configuration.
The viewport will based on the configured fixed aspect ratio if set. If no fixed aspect ratio is set the viewport will be scaled to the entire window size regardless of size.
Will add black borders and center the viewport if the window do not match the configured viewport (fixed only)
- set_icon(icon_path: str) None
Sets the window icon to the given path
- Parameters:
icon_path (str) – path to the icon
- show() None
Show the window
- property size: tuple[int, int]
current window size.
This property also support assignment:
# Resize the window to 1000 x 1000 window.size = 1000, 1000
- Type:
tuple[int, int]
- swap_buffers() None[source]
Placeholder. We currently don’t do double buffering in headless mode. This may change in the future.
- property title: str
Window title.
This property can also be set:
window.title = "New Title"
- Type:
str
- property unicode_char_entered_func: Callable[[str], None]
Get or set the unicode_char_entered callable
- Type:
callable
- property viewport: tuple[int, int, int, int]
current window viewport
- Type:
tuple[int, int, int, int]
- property viewport_height: int
The height of the viewport
Equivalent to
self.viewport[3].- Type:
int
- property viewport_size: tuple[int, int]
Size of the viewport.
Equivalent to
self.viewport[2], self.viewport[3]- Type:
tuple[int,int]
- property viewport_width: int
The width of the viewport.
Equivalent to
self.viewport[2].- Type:
int
- property visible: bool
Window is visible
- Type:
bool
- property vsync: bool
vertical sync enabled/disabled
- Type:
bool
- property width: int
The current window width
- Type:
int