Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am using the easy-to-use Python library pgzero (which uses pygame internally) for programming games.

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

Edit: pgzero uses pygame internally, perhaps there is a change the window mode using the pygame API...

question from:https://stackoverflow.com/questions/65941020/is-there-a-way-to-enable-full-screen-in-python-pgzero

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
313 views
Welcome To Ask or Share your Answers For Others

1 Answer

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(). e.g.:

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):

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()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...