How to indicate where pygame creates a game window

Is there a way to control where pygame creates a game screen? It seems that he always creates it in the same general area, but not in an agreed place.

+8
python screen pygame
source share
2 answers

Window positioning is not handled by the client application. It is handled by the Window dispatcher (metacity, etc.).

The SDL library on which PyGame is based has several environment variables that can be used to provide help in the window manager. These are tips that WM can ignore, but this is the best you can do.

Below are comments on here .

+5
source share
import os os.environ['SDL_VIDEO_WINDOW_POS'] = str(position[0]) + "," + str(position[1]) 

according to http://pygame.org/wiki/FrequentlyAskedQuestions

You can also simply center the screen with

 import pygame, os os.environ['SDL_VIDEO_CENTERED'] = '1' 

Note that this must be done before initializing pygame in the main loop. I do this right after importing os, for example. And since they are not part of pygame, you can probably use it elsewhere, although things like gtk and wxpython provide their own mechanisms.

+13
source share

All Articles