我试图在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()
对于Pygame的早期版本(2.0.0之前),可以通过设置} (至少在某些系统中是这样)来更改窗口位置。} 模块
SDL_VIDEO_WINDOW_POS
并调用^{这不再可能。如果要更改窗口的位置,必须重新初始化^{
pygame.display.quit()
和pygame.display.init()
。在任何情况下,都需要在调用
pygame.display.set_mode()
之前设置SDL_VIDEO_WINDOW_POS
最简单的例子:
如果您在windows上,则可以使用C API通过^{} 移动窗口
与辅助函数一起获得准确位置:
还可以实现相对移动功能
请注意,这些函数设置窗口的左上角,而不是中心
相关问题 更多 >
编程相关推荐