|
60 | 60 | .. class:: Window |
61 | 61 |
|
62 | 62 | | :sl:`pygame object that represents a window` |
63 | | - | :sg:`Window(title='pygame window', size=(640, 480), position=None, fullscreen=False, fullscreen_desktop=False, **kwargs) -> Window` |
64 | | -
|
65 | | - Creates a window. |
66 | | - |
67 | | - :param str title: The title of the window. |
68 | | - :param (int, int) size: The size of the window, in screen coordinates. |
69 | | - :param (int, int) or int position: A tuple specifying the window position, or |
70 | | - ``WINDOWPOS_CENTERED``, or ``WINDOWPOS_UNDEFINED``. |
71 | | - :param bool fullscreen: Create a fullscreen window using the window size as |
72 | | - the resolution (videomode change). |
73 | | - :param bool fullscreen_desktop: Create a fullscreen window using the current |
74 | | - desktop resolution. |
75 | | - :param bool opengl: Create a window with support for an OpenGL context. You |
76 | | - will still need to create an OpenGL context separately. |
77 | | - :param bool vulkan: Create a window with support for a Vulkan instance. |
78 | | - :param bool hidden: Create a hidden window. |
79 | | - :param bool borderless: Create a window without borders. |
80 | | - :param bool resizable: Create a resizable window. |
81 | | - :param bool minimized: Create a mimized window. |
82 | | - :param bool maximized: Create a maximized window. |
83 | | - :param bool mouse_grabbed: Create a window with grabbed mouse input. |
84 | | - :param bool keyboard_grabbed: Create a window with grabbed keyboard input. |
85 | | - :param bool input_focus: Create a window with input focus. |
86 | | - :param bool mouse_focus: Create a window with mouse focus. |
87 | | - :param bool foreign: Marks a window not created by SDL. |
88 | | - :param bool allow_highdpi: Create a window in high-DPI mode if supported. |
89 | | - :param bool mouse_capture: Create a window that has the mouse captured |
90 | | - (unrelated to INPUT_GRABBED). |
91 | | - :param bool always_on_top: Create a window that is always on top |
92 | | - (X11 only). |
93 | | - :param bool skip_taskbar: Create a window that should not be added to the |
94 | | - taskbar (X11 only). |
95 | | - :param bool utility: Create a window that should be treated as a utility |
96 | | - window (X11 only). |
97 | | - :param bool tooltip: Create a window that should be treated as a tooltip |
98 | | - (X11 only). |
99 | | - :param bool popup_menu: Create a window that should be treated as a popup menu |
100 | | - (X11 only). |
101 | | - |
102 | | - |
103 | | - .. attribute:: grab_mouse |
104 | | - |
105 | | - | :sl:`Get or set the window's mouse grab mode` |
106 | | - | :sg:`grab_mouse -> bool` |
107 | | -
|
108 | | - When this attribute is set to ``True``, the window will try to confine the mouse |
109 | | - cursor to itself. |
110 | | - |
111 | | - Note this only set the "mode" of grab. The mouse may be confined to another window |
112 | | - depending on the window focus. To get if the mouse is currently restricted to this |
113 | | - window, please use :attr:`mouse_grabbed`. |
114 | | - |
115 | | - .. seealso:: :attr:`mouse_grabbed` |
116 | | - |
117 | | - .. versionadded:: 2.4.0 |
118 | | - |
119 | | - .. attribute:: grab_keyboard |
120 | | - |
121 | | - | :sl:`Get or set the window's keyboard grab mode` |
122 | | - | :sg:`grab_keyboard -> bool` |
123 | | - |
124 | | - When this attribute is set to ``True``, the window will try to capture system |
125 | | - keyboard shortcuts like ``Alt+Tab`` or the ``Meta/Super`` key. |
126 | | - |
127 | | - This attribute only set the "mode" of grab. The keyboard may be captured by |
128 | | - another window depending on the window focus. To get if keyboard is currently |
129 | | - captured by this window, please use :attr:`keyboard_grabbed`. |
130 | | - |
131 | | - Note that not all system keyboard shortcuts can be captured by applications |
132 | | - (one example is ``Ctrl+Alt+Del`` on Windows). |
133 | | - |
134 | | - When keyboard grab is enabled, pygame will continue to handle ``Alt+Tab`` when |
135 | | - the window is full-screen to ensure the user is not trapped in your application. |
136 | | - If you have a custom keyboard shortcut to exit fullscreen mode, you may suppress |
137 | | - this behavior with an environment variable, e.g. |
138 | | - ``os.environ["SDL_ALLOW_ALT_TAB_WHILE_GRABBED"] = "0"``. |
139 | | - |
140 | | - This attribute requires SDL 2.0.16+. |
141 | | - |
142 | | - .. seealso:: :attr:`keyboard_grabbed` |
143 | | - |
144 | | - .. versionadded:: 2.4.0 |
145 | | - |
146 | | - .. attribute:: mouse_grabbed |
147 | | - |
148 | | - | :sl:`Get if the mouse cursor is confined to the window (**read-only**)` |
149 | | - | :sg:`mouse_grabbed -> bool` |
150 | | -
|
151 | | - Get if the mouse cursor is currently grabbed and confined to the window. |
152 | | - |
153 | | - Roughly equivalent to this expression: |
154 | | - |
155 | | - :: |
156 | | - |
157 | | - win.grab_mouse and (win is get_grabbed_window()) |
158 | | - |
159 | | - .. seealso:: :attr:`grab_mouse` |
160 | | - |
161 | | - .. versionadded:: 2.4.0 |
162 | | - |
163 | | - .. attribute:: keyboard_grabbed |
164 | | - |
165 | | - | :sl:`Get if the keyboard shortcuts are captured by the window (**read-only**)` |
166 | | - | :sg:`keyboard_grabbed -> bool` |
167 | | -
|
168 | | - Get if the keyboard shortcuts are currently grabbed and captured by the window. |
169 | | - |
170 | | - Roughly equivalent to this expression: |
171 | | - |
172 | | - :: |
173 | | - |
174 | | - win.grab_keyboard and (win is get_grabbed_window()) |
175 | | - |
176 | | - This attribute requires SDL 2.0.16+. |
177 | | - |
178 | | - .. seealso:: :attr:`grab_keyboard` |
179 | | - |
180 | | - .. versionadded:: 2.4.0 |
181 | | - |
182 | | - .. attribute:: title |
183 | | - |
184 | | - | :sl:`Get or set the window title` |
185 | | - | :sg:`title -> str` |
186 | | -
|
187 | | - Gets or sets the window title. An empty string means that no title is set. |
188 | | - |
189 | | - .. attribute:: resizable |
190 | | - |
191 | | - | :sl:`Get or set whether the window is resizable` |
192 | | - | :sg:`resizable -> bool` |
193 | | -
|
194 | | - .. attribute:: borderless |
195 | | - |
196 | | - | :sl:`Get or set whether the window is borderless` |
197 | | - | :sg:`borderless -> bool` |
198 | | -
|
199 | | - Gets or sets whether the window is borderless. |
200 | | - |
201 | | - .. note:: You can't change the border state of a fullscreen window. |
202 | | - |
203 | | - .. attribute:: always_on_top |
204 | | - |
205 | | - | :sl:`Get or set whether the window is always on top` |
206 | | - | :sg:`always_on_top -> bool` |
207 | | -
|
208 | | - Get or set whether the window is always on top. |
209 | | - |
210 | | - Setting the always-on-top mode requires SDL 2.0.16+. |
211 | | - |
212 | | - .. versionadded:: 2.3.1 |
213 | | - |
214 | | - .. attribute:: id |
215 | | - |
216 | | - | :sl:`Get the unique window ID (**read-only**)` |
217 | | - | :sg:`id -> int` |
218 | | - |
219 | | - .. attribute:: mouse_rect |
220 | | - |
221 | | - | :sl:`Get or set the mouse confinement rectangle of the window` |
222 | | - | :sg:`mouse_rect -> Rect|None` |
223 | | -
|
224 | | - Setting this attribute to a rect-like object confines the |
225 | | - cursor to the specified area of this window. |
226 | | - |
227 | | - This attribute can be None, meaning that there is no mouse rect. |
228 | | - |
229 | | - Note that this does NOT grab the cursor, it only defines the area a |
230 | | - cursor is restricted to when the window has mouse focus. |
231 | | - |
232 | | - .. versionadded:: 2.4.0 |
233 | | - |
234 | | - .. attribute:: size |
235 | | - |
236 | | - | :sl:`Get or set the window size in pixels` |
237 | | - | :sg:`size -> (int, int)` |
238 | | - |
239 | | - .. attribute:: minimum_size |
240 | | - |
241 | | - | :sl:`Get or set the minimum size of the window's client area` |
242 | | - | :sg:`minimum_size -> (int, int)` |
243 | | -
|
244 | | - Initial value in most cases is ``(0, 0)``. If :func:`from_display_module` |
245 | | - was used to create the window and :func:`pygame.display.set_mode` was |
246 | | - called with the ``SCALED`` flag, the initial value is the size used in |
247 | | - that call. |
248 | | - |
249 | | - Raises a ``ValueError`` if negative values are provided or |
250 | | - if the width or height provided are greater than set |
251 | | - maximum width or height respectively. Unless maximum size |
252 | | - is ``(0, 0)`` (initial value). |
253 | | - |
254 | | - .. seealso:: :attr:`maximum_size`. |
255 | | - |
256 | | - .. versionadded:: 2.4.0 |
257 | | - |
258 | | - .. attribute:: maximum_size |
259 | | - |
260 | | - | :sl:`Get or set the maximum size of the window's client area` |
261 | | - | :sg:`maximum_size -> (int, int)` |
262 | | -
|
263 | | - Initial value is ``(0, 0)``. |
264 | | - |
265 | | - Raises a ``ValueError`` if negative values are provided or |
266 | | - if the width or height provided are less than set minimum |
267 | | - width or height respectively. |
268 | | - |
269 | | - .. seealso:: :attr:`minimum_size`. |
270 | | - |
271 | | - .. versionadded:: 2.4.0 |
272 | | - |
273 | | - .. attribute:: position |
274 | | - |
275 | | - | :sl:`Get or set the window position in screen coordinates` |
276 | | - | :sg:`position -> (int, int) or WINDOWPOS_CENTERED or WINDOWPOS_UNDEFINED` |
277 | | -
|
278 | | - .. attribute:: opacity |
279 | | - |
280 | | - | :sl:`Get or set the window opacity, between 0.0 (fully transparent) and 1.0 (fully opaque)` |
281 | | - | :sg:`opacity -> float` |
282 | | -
|
283 | | - .. attribute:: display_index |
284 | | - |
285 | | - | :sl:`Get the index of the display that owns the window (**read-only**)` |
286 | | - | :sg:`get_display_index -> int` |
287 | | -
|
288 | | - .. classmethod:: from_display_module |
289 | | - |
290 | | - | :sl:`Create a Window object using window data from display module` |
291 | | - | :sg:`from_display_module() -> Window` |
292 | | -
|
293 | | - Create a Window object that uses the same window data from the :mod:`pygame.display` module, created upon calling |
294 | | - :func:`pygame.display.set_mode`. |
295 | | - |
296 | | - .. method:: get_surface |
297 | | - |
298 | | - | :sl:`Get the window surface` |
299 | | - | :sg:`get_surface() -> Surface` |
300 | | -
|
301 | | - Returns a "display surface" for this Window. The surface returned is |
302 | | - analogous to the surface returned by :func:`pygame.display.set_mode`. |
303 | | - |
304 | | - This method allows software rendering (classic pygame rendering) on top |
305 | | - of the Window API. This method should not be called when using hardware |
306 | | - rendering (coming soon). |
307 | | - |
308 | | - Similarly to the "display surface" returned by :mod:`pygame.display`, |
309 | | - this surface will change size with the Window, and will become invalid |
310 | | - after the Window's destruction. |
311 | | - |
312 | | - .. seealso:: :func:`flip` |
313 | | - |
314 | | - .. versionadded:: 2.4.0 |
315 | | - |
316 | | - .. method:: flip |
317 | | - |
318 | | - | :sl:`Update the display surface to the window.` |
319 | | - | :sg:`flip() -> None` |
320 | | -
|
321 | | - Update content from the display surface to the window. This is the Window |
322 | | - class equivalent of :func:`pygame.display.flip`. |
323 | | - |
324 | | - This method allows software rendering (classic pygame rendering) on top |
325 | | - of the Window API. This method should not be called when using hardware |
326 | | - rendering (coming soon). |
327 | | - |
328 | | - Here is a runnable example of using ``get_surface`` and ``flip``: |
329 | | - |
330 | | - .. code-block:: python |
331 | | -
|
332 | | - import pygame |
333 | | - from pygame._sdl2 import video |
334 | | -
|
335 | | - win = video.Window() |
336 | | - surf = win.get_surface() # get the window surface |
337 | | -
|
338 | | - while True: |
339 | | - for event in pygame.event.get(): |
340 | | - if event.type == pygame.QUIT: |
341 | | - pygame.quit() |
342 | | - raise SystemExit |
343 | | -
|
344 | | - # draw something on the surface |
345 | | - surf.fill("red") |
346 | | -
|
347 | | - win.flip() # update the surface to the window |
348 | | -
|
349 | | -
|
350 | | - .. versionadded:: 2.4.0 |
351 | | - |
352 | | - .. method:: set_windowed |
353 | | - |
354 | | - | :sl:`Enable windowed mode (exit fullscreen)` |
355 | | - | :sg:`set_windowed() -> None` |
356 | | -
|
357 | | - .. seealso:: :func:`set_fullscreen` |
358 | | - |
359 | | - .. method:: set_fullscreen |
360 | | - |
361 | | - | :sl:`Enter fullscreen` |
362 | | - | :sg:`set_fullscreen(desktop=False) -> None` |
363 | | -
|
364 | | - :param bool desktop: If ``True``, use the current desktop resolution. |
365 | | - If ``False``, change the fullscreen resolution to the window size. |
366 | | - |
367 | | - .. seealso:: :meth:`set_windowed`. |
368 | | - |
369 | | - .. method:: destroy |
370 | | - |
371 | | - | :sl:`Destroy the window` |
372 | | - | :sg:`destroy() -> None` |
373 | | -
|
374 | | - Destroys the internal window data of this Window object. This method is |
375 | | - called automatically when this Window object is garbage collected, so |
376 | | - there usually aren't any reasons to call it manually. |
377 | | - |
378 | | - Other methods that try to manipulate that window data will raise an error. |
379 | | - |
380 | | - .. method:: hide |
381 | | - |
382 | | - | :sl:`Hide the window` |
383 | | - | :sg:`hide() -> None` |
384 | | -
|
385 | | - .. method:: show |
386 | | - |
387 | | - | :sl:`Show the window` |
388 | | - | :sg:`show() -> None` |
389 | | -
|
390 | | - .. method:: focus |
391 | | - |
392 | | - | :sl:`Set the window to be focused` |
393 | | - | :sg:`focus(input_only=False) -> None` |
394 | | -
|
395 | | - Raises the window above other windows and sets the input focus. |
396 | | - |
397 | | - :param bool input_only: if ``True``, the window will be given input focus |
398 | | - but may be completely obscured by other windows. |
399 | | - Only supported on X11. |
400 | | - |
401 | | - .. method:: restore |
402 | | - |
403 | | - | :sl:`Restore the size and position of a minimized or maximized window` |
404 | | - | :sg:`restore() -> None` |
405 | | -
|
406 | | - .. method:: maximize |
407 | | - |
408 | | - | :sl:`Maximize the window` |
409 | | - | :sg:`maximize() -> None` |
410 | | -
|
411 | | - .. method:: minimize |
412 | | - |
413 | | - | :sl:`Minimize the window` |
414 | | - | :sg:`maximize() -> None` |
415 | | -
|
416 | | - .. method:: set_icon |
417 | | - |
418 | | - | :sl:`Set the window icon` |
419 | | - | :sg:`set_icon(surface, /) -> None` |
420 | | -
|
421 | | - Sets the window icon. |
422 | | - |
423 | | - :param Surface surface: A Surface to use as the icon. |
424 | | - |
425 | | - .. method:: set_modal_for |
426 | | - |
427 | | - | :sl:`Set the window as a modal for a parent window` |
428 | | - | :sg:`set_modal_for(parent, /) -> None` |
429 | | -
|
430 | | - :param Window parent: The parent window. |
431 | | - |
432 | | - .. note:: This function is only supported on X11. |
433 | 63 |
|
| 64 | + See :class:`pygame.Window` |
434 | 65 |
|
435 | 66 | .. class:: Texture |
436 | 67 |
|
|
0 commit comments