I'm trying to set the position of my window in PyGame, but this method doesn't work for me. It says that it's updated when I print it out, but nothing changes visually.
My code:
import pygame as pg
from tkinter import messagebox as mb
import time
import sys
import requests
import os
pg.init()
sc = pg.display.set_mode((1000,750))
try:
testimg143 = open("Data\test.txt", "r")
except:
ud = "ginfo\"
else:
ud = ""
testimg143.close()
#main game loop
gamewindowfullscreen = False
def setgamewindowcenter():
x = 500
y = 100
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (x,y)
print(os.environ['SDL_VIDEO_WINDOW_POS'])
while True:
for event in pg.event.get():
if (event.type == pg.KEYUP):
if (event.key == pg.K_F11):
if (gamewindowfullscreen == False):
sc = pg.display.set_mode((0,0), pg.FULLSCREEN)
setgamewindowcenter()
gamewindowfullscreen = True
else:
sc = pg.display.set_mode((1000,750))
setgamewindowcenter()
gamewindowfullscreen = False
if event.type == pg.QUIT:
pg.quit()
exit()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…