如何在python中使用Pygame-SDL2在第二台显示器上全屏显示?

时间:2020-07-18 22:37:12

标签: python pygame pysdl2

几年前,我看到了几篇文章,介绍了在Pygame中还没有第二个显示器的全屏功能。随着Pygame-SDL2的问世,我想知道如何让我的程序在第二台显示器上全屏显示。我真的不想在新程序中重做所有代码。我正在Windows上运行python。

使用我到目前为止编写的代码,当我尝试将窗口放在第二个监视器上时全屏显示时,它将获得第二个屏幕的分辨率,并将程序和其他窗口放在主屏幕上延伸到第二台显示器上。

这是我的pygame代码部分,我还有另一部分可以处理RGB值数组:

#Setup Python ----------------------------------------------- #
import pygame, sys
import pygame_sdl2
pygame_sdl2.import_as_pygame()
import numpy as np
import time
from tkinter import Tk
from tkinter.filedialog import askopenfilename
from tkinter.filedialog import asksaveasfile
from tkinter import *
 
# Setup pygame/window ---------------------------------------- #
mainClock = pygame.time.Clock()
from pygame.locals import *
pygame.init()

Tk().withdraw() 
filename = askopenfilename() 

Template = np.loadtxt(fname = filename)



white = (255,255,255)
black = (0,0,0)
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
yel = (255,255,0)   #yellow
mag = (255,0,255)    #purple/pink #magenta
cyan = (0,255,255)       #blue

pygame.display.set_caption('game base')
monitor_size = [pygame.display.Info().current_w, pygame.display.Info().current_h]
screen = pygame.display.set_mode((500, 500), pygame.RESIZABLE)
 
fullscreen = False

count = 0
        

while True and count<602:
        
    screen.fill((0, 0, 0))
    
    r = Template[count, 1]
    g = Template[count, 2]
    b = Template[count, 3]
    
    
    
    
    
    var = (r,g,b)
    invar = (255-r,255-g,255-b)
   


#rectangle
    pygame.draw.rect(screen, var, pygame.Rect(screen.get_width()*((1/2)-1/9), screen.get_height()*((1/2)-1/9), screen.get_width()*(2/9), (screen.get_height()*(2/9))))


    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    if event.type == VIDEORESIZE:
        if not fullscreen:
            screen = pygame.display.set_mode((event.w, event.h), pygame.RESIZABLE)
    if event.type == KEYDOWN:
        if event.key == K_ESCAPE:
            pygame.quit()
            sys.exit()
        if event.key == K_f:
            fullscreen = not fullscreen
            if fullscreen:
                screen = pygame.display.set_mode(monitor_size, pygame.FULLSCREEN)
            else:
                screen = pygame.display.set_mode((screen.get_width(), screen.get_height()), pygame.RESIZABLE)
            

    count=count+1;
    time.sleep(0.001)
    
 
    pygame.display.update()
    mainClock.tick(60)

0 个答案:

没有答案