Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open pygame fullscreen window in secondary monitor

Tags:

python

pygame

I'm trying to build a simple game to be projected onto a table to do a small AR demo.

To do this, I need to open the game window in fullscreen mode on a second monitor (projector). I have seen in other questions asked here that there is no way to do this directly in pygame. Can anyone suggest me another way to open a pygame window on a separate display?

like image 953
rjns Avatar asked Sep 21 '25 00:09

rjns


2 Answers

I found the answer to my problem by using SDL environment variables before initializing pygame:

x = 0
y = 0
os.environ['SDL_VIDEO_WINDOW_POS'] = f"{x},{y}"

By specifying x, the left border of the window will open in that location.

e.g. If you have two monitors with resolution 1920*1080 and x=0, the window will open in the left monitor; if x=1920 it will opened in the right monitor.

Since I also want the window to be fullcreen without a border I specify the flag NOFRAME in set_mode:

screen = pygame.display.set_mode((screen_width, screen_height), flags = pygame.NOFRAME)
like image 75
rjns Avatar answered Sep 22 '25 13:09

rjns


No way to test(now) if that solves exactly your problem, but display has

set_mode(size=(0, 0), flags=0, depth=0, display=0)

which features display argument

like image 33
Marcel Rzepka Avatar answered Sep 22 '25 15:09

Marcel Rzepka