Window using PyQt5.

This is the recommended window if you want your project to work on most platforms out of the box without any binary dependecies.


Namespace creating pyqt specific key constants



Creates a pyqt application and window overriding the built in event loop. Sets up keyboard and mouse events and creates a monderngl.Context.


Pyqt specific key press callback function. Translates and forwards events to keyboard_event().


Pyqt specific key release callback function. Translates and forwards events to keyboard_event().


Pyqt specific mouse event callback Translates and forwards events to cursor_event().


Swaps buffers, increments the frame counter and pulls events


Make the window’s framebuffer the current render target

Window.should_close() → bool

Checks if the internal close state is set


Set the internal close state


Quits the running qt application

Window.resize(width, height)

Pyqt specific resize callback.

Other Inherited Methods

Window.draw(current_time, frame_time)

Draws a frame. Internally it calls the configured timeline’s draw method.

  • current_time (float) – The current time (preferrably always from the configured timer class)
  • frame_time (float) – The duration of the previous frame in seconds

Clear the window buffer

Window.clear_values(red=0.0, green=0.0, blue=0.0, alpha=0.0, depth=1.0)

Sets the clear values for the window buffer.

  • red (float) – red compoent
  • green (float) – green compoent
  • blue (float) – blue compoent
  • alpha (float) – alpha compoent
  • depth (float) – depth value
Window.keyboard_event(key, action, modifier)

Handles the standard keyboard events such as camera movements, taking a screenshot, closing the window etc.

Can be overriden add new keyboard events. Ensure this method is also called if you want to keep the standard features.

  • key – The key that was pressed or released
  • action – The key action. Can be ACTION_PRESS or ACTION_RELEASE
  • modifier – Modifiers such as holding shift or ctrl
Window.cursor_event(x, y, dx, dy)

The standard mouse movement event method. Can be overriden to add new functionality. By default this feeds the system camera with new values.

  • x – The current mouse x position
  • y – The current mouse y position
  • dx – Delta x postion (x position difference from the previous event)
  • dy – Delta y postion (y position difference from the previous event)

Prints moderngl context info.


Calculates the viewport based on the configured aspect ratio in settings. Will add black borders if the window do not match the viewport.



(width, height) tuple containing the window size.

Note that for certain displays we rely on buffer_size() to get the actual window buffer size. This is fairly common for retina and 4k displays where the UI scale is > 1.0


(width, heigh) buffer size of the window.

This is the actual buffer size of the window taking UI scale into account. A 1920 x 1080 window running in an environment with UI scale 2.0 would have a 3840 x 2160 window buffer.

Window.keys = <class 'demosys.context.pyqt.keys.Keys'>