简体   繁体   English

如何使 Pygame Zero 窗口全屏?

[英]How to make a Pygame Zero window full screen?

I am using the easy-to-use Python library pgzero (which uses pygame internally) for programming games.我正在使用易于使用的 Python 库 pgzero(内部使用pygame )来编写游戏。

How can I make the game window full screen?如何让游戏窗口全屏?

import pgzrun

TITLE = "Hello World"

WIDTH  = 800
HEIGHT = 600

pgzrun.go()

Note: I am using the runtime helper lib pgzrun to make the game executable without an OS shell command... It implicitly imports the pgzero lib...注意:我正在使用运行时帮助程序库 pgzrun 使游戏在没有 OS shell 命令的情况下可执行...它隐式导入 pgzero 库...

Edit: pgzero uses pygame internally, perhaps there is a change the window mode using the pygame API...编辑:pgzero 在内部使用 pygame,也许使用pygame API 改变了窗口模式...

You can access the pygame surface which represents the game screen by screen.surface and you can change the surface in draw() by pygame.display.set_mode() .您可以通过screen.surface访问代表游戏屏幕的 pygame 表面,您可以通过pygame.display.set_mode()draw()中更改表面。 eg:例如:

import pgzrun
import pygame

TITLE = "Hello World"

WIDTH  = 800
HEIGHT = 600

def draw():
    screen.surface = pygame.display.set_mode((WIDTH, HEIGHT), pygame.FULLSCREEN)

pgzrun.go()

Or switch to fullscreen when the f key is pressed respectively return to window mode when the w key is pressed in the key down event ( on_key_down ):或者当按下f键时切换到全屏分别在按下键事件( on_key_down )中按下w键时返回窗口模式:

import pgzrun
import pygame

TITLE = "Hello World"

WIDTH  = 800
HEIGHT = 600

def on_key_down(key):
    if key == keys.F:
        screen.surface = pygame.display.set_mode((WIDTH, HEIGHT), pygame.FULLSCREEN)
    elif key == keys.W:
        screen.surface = pygame.display.set_mode((WIDTH, HEIGHT))

pgzrun.go()
import pgzrun
import pygame

TITLE = "Hello World"

WIDTH  = 800
HEIGHT = 600

def draw():
    screen.surface = pygame.display.set_mode((WIDTH, HEIGHT), pygame.FULLSCREEN)

pgzrun.go()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM