|
46 | 46 |
|
47 | 47 | Event behavior if one Window is created: When the close button is pressed, |
48 | 48 | the ``QUIT`` event will be sent to the event queue. |
49 | | - .. code-block:: python |
50 | | - |
51 | | - import pygame |
52 | 49 |
|
53 | | - window = pygame.Window() |
| 50 | + .. code-block:: python |
54 | 51 |
|
55 | | - while True: |
56 | | - for event in pygame.event.get(): |
57 | | - if event.type == pygame.QUIT: |
58 | | - pygame.quit() |
59 | | - raise SystemExit |
| 52 | + import pygame |
| 53 | +
|
| 54 | + window = pygame.Window() |
| 55 | +
|
| 56 | + while True: |
| 57 | + for event in pygame.event.get(): |
| 58 | + if event.type == pygame.QUIT: |
| 59 | + pygame.quit() |
| 60 | + raise SystemExit |
60 | 61 |
|
61 | 62 | Event behavior if multiple Windows are created: When the close button is |
62 | 63 | pressed, a ``WINDOWCLOSE`` event is sent. You need to explicitly destroy |
63 | 64 | the window. Note that the event ``QUIT`` will only be sent if all Window |
64 | 65 | has been destroyed. |
65 | | - .. code-block:: python |
66 | | - |
67 | | - import pygame |
68 | 66 |
|
69 | | - window1 = pygame.Window(position=(0,100)) |
70 | | - window2 = pygame.Window(position=(700,100)) |
| 67 | + .. code-block:: python |
71 | 68 |
|
72 | | - while True: |
73 | | - for event in pygame.event.get(): |
74 | | - if event.type == pygame.WINDOWCLOSE: |
75 | | - id = event.window.id |
76 | | - print(f"WINDOWCLOSE event sent to Window #{id}.") |
77 | | - event.window.destroy() |
| 69 | + import pygame |
78 | 70 |
|
79 | | - if event.type == pygame.QUIT: |
80 | | - print(f"Last window is destroyed. QUIT event was sent.") |
81 | | - pygame.quit() |
82 | | - raise SystemExit |
| 71 | + window1 = pygame.Window(position=(0,100)) |
| 72 | + window2 = pygame.Window(position=(700,100)) |
| 73 | +
|
| 74 | + while True: |
| 75 | + for event in pygame.event.get(): |
| 76 | + if event.type == pygame.WINDOWCLOSE: |
| 77 | + id = event.window.id |
| 78 | + print(f"WINDOWCLOSE event sent to Window #{id}.") |
| 79 | + event.window.destroy() |
| 80 | +
|
| 81 | + if event.type == pygame.QUIT: |
| 82 | + print(f"Last window is destroyed. QUIT event was sent.") |
| 83 | + pygame.quit() |
| 84 | + raise SystemExit |
83 | 85 |
|
84 | 86 | .. versionadded:: 2.4.0 |
85 | 87 | .. versionchanged:: 2.5.0 when ``opengl`` is ``True``, the ``Window`` has an OpenGL context created by pygame |
|
0 commit comments