Pygame选择要在全屏模式下使用的显示器 [英] Pygame choose which display to use in fullscreen

查看:79
本文介绍了Pygame选择要在全屏模式下使用的显示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码:

#!/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键,它将在第一台监视器上全屏显示.如何选择要全屏显示的显示器?

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?

推荐答案

我对pygame(1.9.x)/SDL<的了解2是因为它不支持双屏幕配置,所以您不能选择屏幕.

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.

它将随着pygame_sdl2一起更改,但尚未准备就绪.

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)

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

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...

也许,请尝试 pyglet 做您想要的事情.

Maybe, try pyglet to do what you want.

这篇关于Pygame选择要在全屏模式下使用的显示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆