【问题标题】:Pygame choose which display to use in fullscreen [duplicate]Pygame选择全屏使用哪个显示器[重复]
【发布时间】:2024-01-03 03:17:01
【问题描述】:

这是代码:

#!/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)

当我按 F 键时,它会切换全屏。但是,如果我运行程序,将窗口移动到第二台显示器,然后按 F,它会在第一台显示器上显示全屏。如何选择要全屏显示的显示器?

【问题讨论】:

标签: python python-2.7 pygame fullscreen


【解决方案1】:

我对pygame (1.9.x) / SDL

它会随着 pygame_sdl2 的变化而改变,但它还没有准备好。

确实,您的代码应该会重新影响屏幕:

        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)

对于我的双屏配置,pygame做了一些奇怪的事情,切换到全屏在屏幕1上做全屏(在这种情况下它不检测全屏使用),然后在两个屏幕上,(这次检测到全屏模式, 等等) 然后返回窗口模式...

也许,试试pyglet 做你想做的事。

【讨论】:

  • 我很难在 pygame 中写东西...现在我必须转向 pyglet 吗?
  • pygame 不支持你需要的东西,所以.... 你可以:等待github.com/renpy/pygame_sdl2 或转移到另一个框架。 Pygame 非常老:最后一个稳定版本:1.9.1 / 2009 年 8 月 6 日; 6 年前