简体   繁体   中英

Open pygame fullscreen window in secondary monitor

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?

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.

eg 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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM