I am working with pygamezero using an editor called MU (this has the pgzero module built in). When the code is executed the top left of the game window spawns from the centre of the screen and, depending on the dimensions provided by the user for height and width and their screen resolution, portions of the window often appears "off screen". I have found a method - using pygame - that evokes full screen, but am wondering if there is a method to set starting x/y coords of the game screen, so that it is not full-screen, but the window spawn position can be controlled.
-
2Try something like ```os.environ['SDL_VIDEO_CENTERED'] = '1'```. You will first need to ```import os```. – befunkt Jul 27 '21 at 23:13
-
Does this answer your question? [How can i change the position of a Surface(Game Window) with respect to computer Screen in PyGame?](https://stackoverflow.com/questions/24730142/how-can-i-change-the-position-of-a-surfacegame-window-with-respect-to-computer) – William Baker Morrison Feb 16 '22 at 16:09
1 Answers
To control the window position in Pygame Zero (pgzrun
) make use of os.environ['SDL_VIDEO_WINDOW_POS']
as shown below. It must happen before the import pgzrun
call, otherwise it won't work.
FYI If you're using Thonny--a teaching & learning IDE--you need to disable Pygame Zero mode
from the Run
menu to control where the window appears. If you don't disable the mode, Thonny will override your choice by implicitly importing (& thus executing) pgzrun
.
The following code snippet will place your window at the top-left corner of the screen. You can also make the window go fullscreen in a different way but that doesn't require os.environ
.
x = 0
y = 0
import os
os.environ['SDL_VIDEO_WINDOW_POS'] = f'{x},{y}'
import pgzrun
pgzrun.go()
Note: This question has also been (pretty much) answered elsewhere. Because this question and answer specifically relate to Pygame Zero I'm adding this here so anyone looking specifically for a pygame zero solution can find it.

- 1,363
- 13
- 9
-
So many related answers. None properly linked: https://stackoverflow.com/questions/44520491/can-i-move-the-pygame-game-window-around-the-screen-pygame – Eric D Jun 07 '22 at 00:47