PyGame os.environ SDL_VIDEO_WINDOW_POS 不起作用

PyGame os.environ SDL_VIDEO_WINDOW_POS does not work(PyGame os.environ SDL_VIDEO_WINDOW_POS 不起作用)
本文介绍了PyGame os.environ SDL_VIDEO_WINDOW_POS 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试在 PyGame 中设置窗口的位置,但这种方法对我不起作用.它说当我打印出来时它已更新,但视觉上没有任何变化.

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.

我的代码:

    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.set_mode()(至少在某些系统中.
这已经不可能了.如果你想改变窗口的位置,你必须重新初始化 display 模块 pygame.display.quit() pygame.display.init().
在任何情况下,都需要在调用 pygame.display.set_mode() 之前设置 SDL_VIDEO_WINDOW_POS.

With earlier version of Pygame (before 2.0.0), the window position could be change by setting SDL_VIDEO_WINDOW_POS and calling pygame.display.set_mode() (at least at some systems.
This is no longer possible. If you want to change the position of the window you have to reinitialize the display module pygame.display.quit() and pygame.display.init().
In any case SDL_VIDEO_WINDOW_POS needs to be set before calling pygame.display.set_mode().

小例子:

import pygame as pg
import os

def setgamewindowcenter(x = 500, y = 100):
    os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (x,y)
    print(os.environ['SDL_VIDEO_WINDOW_POS'])

pg.init()
setgamewindowcenter()
sc = pg.display.set_mode((1000, 750))

gamewindowfullscreen = False
run = True
while run:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            run = False

        if event.type == pg.KEYUP:
            if event.key == pg.K_F11:
                if gamewindowfullscreen == False:
                    sc = pg.display.set_mode((0,0), pg.FULLSCREEN)
                    gamewindowfullscreen = True
                else:
                    pg.display.quit()
                    setgamewindowcenter()
                    pg.display.init()
                    sc = pg.display.set_mode((1000, 750))
                    gamewindowfullscreen = False
                    
pg.quit()
exit()

这篇关于PyGame os.environ SDL_VIDEO_WINDOW_POS 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)