要使用哪個顯示這是代碼: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,它會在第一臺顯示器上顯示全屏。我如何選擇要顯示全屏的顯示器?
你可以看到http://stackoverflow.com/questions/7097163/pygame-dual-monitors-and-fullscreen –
太好了。我不知道如何使用線程。 –