2015-12-30 67 views
0

要使用哪個顯示這是代碼: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,它會在第一臺顯示器上顯示全屏。我如何選擇要顯示全屏的顯示器?

+0

你可以看到http://stackoverflow.com/questions/7097163/pygame-dual-monitors-and-fullscreen –

+0

太好了。我不知道如何使用線程。 –

回答

0

我對pygame(1.9.x)/ SDL <的瞭解是它不支持雙屏配置,所以不能選擇屏幕。

這將改變pygame_sdl2,但它還沒有準備好。

事實上,你的代碼應該reaffect屏幕:

 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做你想做的。

+0

我很難在pygame中編寫東西......現在我必須轉到pyglet了嗎? –

+0

pygame不支持你所需要的,所以....你可以:等待https://github.com/renpy/p​​ygame_sdl2或移動到另一個框架。Pygame已經很老了:上次穩定版本:2009年8月1日1.9/6; 6年前 –