Pygame choose which display to use in fullscreen [duplicate]

喜你入骨 提交于 2021-02-11 15:40:23

问题


This is the code:

#!/usr/bin/python

import pygame, sys
from pygame.locals import *
import Tkinter as tk

root = tk.Tk()

pygame.init()

w = 640
h = 400

RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
YELLOW = (255, 255, 0)
PINK = (255, 0, 255)
CYAN = (0, 255, 255)
WHITE = (255, 255, 255)

screen = pygame.display.set_mode((w,h), RESIZABLE)
clock = pygame.time.Clock()
x = y = 100

tbar = False

Lbutton = Mbutton = Rbutton = MouseX = MouseY = None

logo = pygame.image.load("C:\\Users\\chef\\Desktop\\slogo.png").convert()

while 1:
    for event in pygame.event.get():
        screen.fill(WHITE)
        MouseX, MouseY = pygame.mouse.get_pos()
        Lbutton, Mbutton, Rbutton = pygame.mouse.get_pressed()
        pygame.draw.rect(screen, GREEN, ((0, h-40),(w,h)))
        if event.type == pygame.QUIT:
            sys.exit()  
        elif event.type==VIDEORESIZE:
            w = event.dict['size'][0]
            h = event.dict['size'][1]
            screen=pygame.display.set_mode(event.dict['size'],RESIZABLE)
        elif h - 50 < MouseY < h and MouseX <= 40 and Lbutton or screen.get_at(pygame.mouse.get_pos()) == (255, 0, 0, 255):
            tbar = True
        elif MouseY < h-50 or MouseX > 40 or Lbutton == False:
            tbar = False
        if tbar == True:
            pygame.draw.rect(screen, RED, ((0, h/2), (w/5, h/2-40)))
        if event.type is KEYDOWN and event.key == K_f:
            if screen.get_flags() & FULLSCREEN:
                w = 640
                h = 400
                pygame.display.set_mode((w,h))
            else:
                w = root.winfo_screenwidth()
                h = root.winfo_screenheight()
                pygame.display.set_mode((w,h), FULLSCREEN)
    screen.blit(logo, ((0, h-40),(40, h)))
    pygame.display.flip()
    clock.tick(60)

When I press the key F, it toggles fullscreen. However, if I run the program, move the window to the 2nd monitor, then press F, it shows fullscreen on the 1st monitor. How can I select which monitor to show fullscreen?


回答1:


What I know about pygame (1.9.x) / SDL < 2 is it's don't support dual screen configuration, so, you can't choose the screen.

It will change with pygame_sdl2, but it's not ready yet.

Indeed, your code should reaffect screen :

        if screen.get_flags() & FULLSCREEN:
            w = 640
            h = 400
            screen = pygame.display.set_mode((w,h), RESIZABLE)
        else:
            w = root.winfo_screenwidth()
            h = root.winfo_screenheight()
            screen = pygame.display.set_mode((w,h), FULLSCREEN)

For my dual screen configuration, pygame do some strange things, toggle to fullscreen do fullscreen on screen 1 (it don't detect fullscreen usage in this case), and next on two screen, (this time, fullscreen mode is detected, and so) and next return to windowed mode...

Maybe, try pyglet to do what you want.



来源:https://stackoverflow.com/questions/34526835/pygame-choose-which-display-to-use-in-fullscreen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!