pygame.Window — pygame-ce v2.4.0 documentation

##### pygame-ce documentation

Pygame-ce Home || Help Contents || Reference Index

Most useful stuff: Color | display | draw | event | font | image | key | locals | mixer | mouse | Rect | Surface | time | music | pygame

Advanced stuff: cursors | joystick | mask | sprite | transform | BufferProxy | freetype | gfxdraw | midi | PixelArray | pixelcopy | sndarray | surfarray | math

Other: camera | controller | examples | scrap | system | tests | touch | version

pygame.Window
  pygame object that represents a window
  Window(title='pygame window', size=(640, 480), position=None, fullscreen=False, fullscreen_desktop=False, **kwargs) -> Window

  The Window class (formerly known as _sdl2.video.Window), is an experimental feature of pygame-ce. This class allows for programs to drive multiple Windows on-screen at once, something not possible with the `pygame.display.set_mode()`Initialize a window or screen for display API. Not everything possible with `pygame.display`pygame module to control the display window and screen is possible yet in the Window API, but the new window class will continue to be developed, and we're excited to share the new functionality this class offers.

  Parameters:

    - title (str) -- The title of the window.

    - size ((int, int)) -- The size of the window, in screen coordinates.

    - position ((int, int) or int) -- A tuple specifying the window position, or `WINDOWPOS_CENTERED`, or `WINDOWPOS_UNDEFINED`.

    - fullscreen (bool) -- Create a fullscreen window using the window size as the resolution (videomode change).

    - fullscreen_desktop (bool) -- Create a fullscreen window using the current desktop resolution.

    - opengl (bool) -- Create a window with support for an OpenGL context. You will still need to create an OpenGL context separately.

    - vulkan (bool) -- Create a window with support for a Vulkan instance.

    - hidden (bool) -- Create a hidden window.

    - borderless (bool) -- Create a window without borders.

    - resizable (bool) -- Create a resizable window.

    - minimized (bool) -- Create a mimized window.

    - maximized (bool) -- Create a maximized window.

    - mouse_grabbed (bool) -- Create a window with grabbed mouse input.

    - keyboard_grabbed (bool) -- Create a window with grabbed keyboard input.

    - input_focus (bool) -- Create a window with input focus.

    - mouse_focus (bool) -- Create a window with mouse focus.

    - foreign (bool) -- Marks a window not created by SDL.

    - allow_highdpi (bool) -- Create a window in high-DPI mode if supported.

    - mouse_capture (bool) -- Create a window that has the mouse captured (unrelated to INPUT_GRABBED).

    - always_on_top (bool) -- Create a window that is always presented above others.

  New in pygame-ce 2.4.0.

  grab_mouse
    Get or set the window's mouse grab mode
    grab_mouse -> bool

    When this attribute is set to `True`, the window will try to confine the mouse cursor to itself.

    Note this only set the "mode" of grab. The mouse may be confined to another window depending on the window focus. To get if the mouse is currently restricted to this window, please use `mouse_grabbed`.

    See also

    `mouse_grabbed`

    New in pygame-ce 2.4.0.

  grab_keyboard
    Get or set the window's keyboard grab mode
    grab_keyboard -> bool

    When this attribute is set to `True`, the window will try to capture system keyboard shortcuts like `Alt+Tab` or the `Meta/Super` key.

    This attribute only set the "mode" of grab. The keyboard may be captured by another window depending on the window focus. To get if keyboard is currently captured by this window, please use `keyboard_grabbed`.

    Note that not all system keyboard shortcuts can be captured by applications (one example is `Ctrl+Alt+Del` on Windows).

    When keyboard grab is enabled, pygame will continue to handle `Alt+Tab` when the window is full-screen to ensure the user is not trapped in your application. If you have a custom keyboard shortcut to exit fullscreen mode, you may suppress this behavior with an environment variable, e.g. `os.environ["SDL_ALLOW_ALT_TAB_WHILE_GRABBED"] = "0"`.

    This attribute requires SDL 2.0.16+.

    See also

    `keyboard_grabbed`

    New in pygame-ce 2.4.0.

  mouse_grabbed
    Get if the mouse cursor is confined to the window (**read-only**)
    mouse_grabbed -> bool

    Get if the mouse cursor is currently grabbed and confined to the window.

    Roughly equivalent to this expression:

        win.grab_mouse and (win is get_grabbed_window())

    See also

    `grab_mouse`

    New in pygame-ce 2.4.0.

  keyboard_grabbed
    Get if the keyboard shortcuts are captured by the window (**read-only**)
    keyboard_grabbed -> bool

    Get if the keyboard shortcuts are currently grabbed and captured by the window.

    Roughly equivalent to this expression:

        win.grab_keyboard and (win is get_grabbed_window())

    This attribute requires SDL 2.0.16+.

    See also

    `grab_keyboard`

    New in pygame-ce 2.4.0.

  title
    Get or set the window title
    title -> str

    Gets or sets the window title. An empty string means that no title is set.

  resizable
    Get or set whether the window is resizable
    resizable -> bool
  borderless
    Get or set whether the window is borderless
    borderless -> bool

    Gets or sets whether the window is borderless.

    Note

    You can't change the border state of a fullscreen window.

  always_on_top
    Get or set whether the window is always on top
    always_on_top -> bool

    Get or set whether the window is always on top.

    Setting the always-on-top mode requires SDL 2.0.16+.

    New in pygame-ce 2.3.1.

  id
    Get the unique window ID (**read-only**)
    id -> int
  mouse_rect
    Get or set the mouse confinement rectangle of the window
    mouse_rect -> Rect|None

    Setting this attribute to a rect-like object confines the cursor to the specified area of this window.

    This attribute can be None, meaning that there is no mouse rect.

    Note that this does NOT grab the cursor, it only defines the area a cursor is restricted to when the window has mouse focus.

    New in pygame-ce 2.4.0.

  size
    Get or set the window size in pixels
    size -> (int, int)
  minimum_size
    Get or set the minimum size of the window's client area
    minimum_size -> (int, int)

    Initial value in most cases is `(0, 0)`. If `from_display_module()` was used to create the window and `pygame.display.set_mode()`Initialize a window or screen for display was called with the `SCALED` flag, the initial value is the size used in that call.

    Raises a `ValueError` if negative values are provided or if the width or height provided are greater than set maximum width or height respectively. Unless maximum size is `(0, 0)` (initial value).

    See also

    `maximum_size`.

    New in pygame-ce 2.4.0.

  maximum_size
    Get or set the maximum size of the window's client area
    maximum_size -> (int, int)

    Initial value is `(0, 0)`.

    Raises a `ValueError` if negative values are provided or if the width or height provided are less than set minimum width or height respectively.

    See also

    `minimum_size`.

    New in pygame-ce 2.4.0.

  position
    Get or set the window position in screen coordinates
    position -> (int, int) or WINDOWPOS_CENTERED or WINDOWPOS_UNDEFINED
  opacity
    Get or set the window opacity, between 0.0 (fully transparent) and 1.0 (fully opaque)
    opacity -> float
  classmethod from_display_module()
    Create a Window object using window data from display module
    from_display_module() -> Window

    DON'T USE THIS! If you want to draw to a surface and use the window API, use `Window.get_surface()` and `Window.flip()`.

    Create a Window object that uses the same window data from the `pygame.display`pygame module to control the display window and screen module, created upon calling `pygame.display.set_mode()`Initialize a window or screen for display.

    Deprecated since pygame-ce 2.4.0.

  get_surface()
    Get the window surface
    get_surface() -> Surface

    Returns a "display surface" for this Window. The surface returned is analogous to the surface returned by `pygame.display.set_mode()`Initialize a window or screen for display.

    This method allows software rendering (classic pygame rendering) on top of the Window API. This method should not be called when using hardware rendering (coming soon).

    Similarly to the "display surface" returned by `pygame.display`pygame module to control the display window and screen, this surface will change size with the Window, and will become invalid after the Window's destruction.

    See also

    `flip()`

    New in pygame-ce 2.4.0.

  flip()
    Update the display surface to the window.
    flip() -> None

    Update content from the display surface to the window. This is the Window class equivalent of `pygame.display.flip()`Update the full display Surface to the screen.

    This method allows software rendering (classic pygame rendering) on top of the Window API. This method should not be called when using hardware rendering (coming soon).

    Here is a runnable example of using `get_surface` and `flip`:

        import pygame

        win = pygame.Window()
        surf = win.get_surface()  # get the window surface

        while True:
           for event in pygame.event.get():
              if event.type == pygame.QUIT:
                    pygame.quit()
                    raise SystemExit

           # draw something on the surface
           surf.fill("red")

           win.flip()  # update the surface to the window

    New in pygame-ce 2.4.0.

  set_windowed()
    Enable windowed mode (exit fullscreen)
    set_windowed() -> None

    See also

    `set_fullscreen()`

  set_fullscreen()
    Enter fullscreen
    set_fullscreen(desktop=False) -> None
    Parameters:

      desktop (bool) -- If `True`, use the current desktop resolution. If `False`, change the fullscreen resolution to the window size.

    See also

    `set_windowed()`.

  destroy()
    Destroy the window
    destroy() -> None

    Destroys the internal window data of this Window object. This method is called automatically when this Window object is garbage collected, so there usually aren't any reasons to call it manually.

    Other methods that try to manipulate that window data will raise an error.

  hide()
    Hide the window
    hide() -> None
  show()
    Show the window
    show() -> None
  focus()
    Set the window to be focused
    focus(input_only=False) -> None

    Raises the window above other windows and sets the input focus.

    Parameters:

      input_only (bool) -- if `True`, the window will be given input focus but may be completely obscured by other windows. Only supported on X11.

  restore()
    Restore the size and position of a minimized or maximized window
    restore() -> None
  maximize()
    Maximize the window
    maximize() -> None
  minimize()
    Minimize the window
    maximize() -> None
  set_icon()
    Set the window icon
    set_icon(surface, /) -> None

    Sets the window icon.

    Parameters:

      surface (Surface) -- A Surface to use as the icon.

  set_modal_for()
    Set the window as a modal for a parent window
    set_modal_for(parent, /) -> None
    Parameters:

      parent (Window) -- The parent window.

    Note

    This function is only supported on X11.

Edit on GitHub