Pygame 简单实例(5)窗口在固定尺寸和全屏之间切换

# coding=utf-8

import pygame
from pygame.locals import *
from sys import exit
# 初始化
pygame.init()
pygame.display.set_caption("按下F1可进行全屏和固定尺寸的切换")

background_image='front.png'
screen=pygame.display.set_mode((640,480),0,32)
background=pygame.image.load(background_image).convert()

fullscreen=False

while True:
    for event in pygame.event.get():
        if event.type==QUIT:
            exit()
        if event.type==KEYDOWN:
            if event.key==K_F1:
                fullscreen=not fullscreen
                if fullscreen:
                    screen=pygame.display.set_mode((640,480),FULLSCREEN,32)
                else:
                    screen=pygame.display.set_mode((640,480),0,32)
    screen.blit(background,(0,0))
    pygame.display.update()

结果:按下F1可进行窗口全屏与固定尺寸的切换(这个程序还是有点问题,切换为全屏后切不回来了)

你可能感兴趣的:(python练习)