From 85ef5318597ca12af53c444c89420d6c689b7de2 Mon Sep 17 00:00:00 2001 From: MrValdez Date: Mon, 23 Sep 2024 16:29:49 +0800 Subject: [PATCH 1/2] added example on how Window behaves with WINDOWCLOSE and QUIT events --- docs/reST/ref/window.rst | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/reST/ref/window.rst b/docs/reST/ref/window.rst index a8ecbbdaa7..68e89a6645 100644 --- a/docs/reST/ref/window.rst +++ b/docs/reST/ref/window.rst @@ -44,6 +44,38 @@ :param bool always_on_top: Create a window that is always presented above others. + Event behavior if one Window is created: When the close button is pressed, the ``QUIT`` event will be sent to the event queue. + .. code-block:: python + + import pygame + + window = pygame.Window() + + while True: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + pygame.quit() + raise SystemExit + + Event behavior if multiple Windows are created: When the close button is pressed, a ``WINDOWCLOSE`` event is sent. You need to explicitly destroy the window. Note that the event ``QUIT`` will only be sent if all Window has been destroyed. + .. code-block:: python + + import pygame + + window1 = pygame.Window(position=(0,100)) + window2 = pygame.Window(position=(700,100)) + + while True: + for event in pygame.event.get(): + if event.type == pygame.WINDOWCLOSE: + print(f"WINDOWCLOSE event sent to Window #{event.window.id}.") + event.window.destroy() + + if event.type == pygame.QUIT: + print(f"Last window is destroyed. QUIT event was sent.") + pygame.quit() + raise SystemExit + .. versionadded:: 2.4.0 .. versionchanged:: 2.5.0 when ``opengl`` is ``True``, the ``Window`` has an OpenGL context created by pygame .. versionchanged:: 2.5.1 Window is now a base class, allowing subclassing From aa7d279aeb3663849130e2cfb62a69e98b83c523 Mon Sep 17 00:00:00 2001 From: MrValdez Date: Mon, 23 Sep 2024 17:02:56 +0800 Subject: [PATCH 2/2] reformatted to fit character limit --- docs/reST/ref/window.rst | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/reST/ref/window.rst b/docs/reST/ref/window.rst index 68e89a6645..5a1877e37b 100644 --- a/docs/reST/ref/window.rst +++ b/docs/reST/ref/window.rst @@ -44,7 +44,8 @@ :param bool always_on_top: Create a window that is always presented above others. - Event behavior if one Window is created: When the close button is pressed, the ``QUIT`` event will be sent to the event queue. + Event behavior if one Window is created: When the close button is pressed, + the ``QUIT`` event will be sent to the event queue. .. code-block:: python import pygame @@ -57,7 +58,10 @@ pygame.quit() raise SystemExit - Event behavior if multiple Windows are created: When the close button is pressed, a ``WINDOWCLOSE`` event is sent. You need to explicitly destroy the window. Note that the event ``QUIT`` will only be sent if all Window has been destroyed. + Event behavior if multiple Windows are created: When the close button is + pressed, a ``WINDOWCLOSE`` event is sent. You need to explicitly destroy + the window. Note that the event ``QUIT`` will only be sent if all Window + has been destroyed. .. code-block:: python import pygame @@ -68,7 +72,8 @@ while True: for event in pygame.event.get(): if event.type == pygame.WINDOWCLOSE: - print(f"WINDOWCLOSE event sent to Window #{event.window.id}.") + id = event.window.id + print(f"WINDOWCLOSE event sent to Window #{id}.") event.window.destroy() if event.type == pygame.QUIT: