我试图在pygame中设置窗口的位置,但这种方法对我不起作用。它说当我打印出来时它会更新,但是视觉上没有任何变化。
我的代码:
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()
1条答案
按热度按时间vcudknz31#
对于pygame的早期版本(2.0.0之前),可以通过设置更改窗口位置
SDL_VIDEO_WINDOW_POS
和呼唤pygame.display.set_mode()
(至少在某些系统。这已经不可能了。如果要更改窗口的位置,必须重新初始化
display
模块pygame.display.quit()
及pygame.display.init()
.无论如何
SDL_VIDEO_WINDOW_POS
需要在调用之前进行设置pygame.display.set_mode()
.最简单的例子: