Pygame选择在全屏中使用哪个显示器

时间:2015-12-30 09:40:35

标签: python python-2.7 pygame fullscreen

这是代码:

#!/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,它会在第一个显示器上显示全屏。如何选择要显示全屏的显示器?

1 个答案:

答案 0 :(得分:0)

我对pygame(1.9.x)/ SDL&lt; 2是它不支持双屏配置,因此,您无法选择屏幕。

它会随着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做你想做的事。