如何在 PyGame 中最大化显示屏幕? [英] How do I maximize the display screen in PyGame?

查看:76
本文介绍了如何在 PyGame 中最大化显示屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Python 编程的新手,最近开始使用 PyGame 模块.下面是一段简单的代码来初始化一个显示屏幕.我的问题是:目前,最大化按钮被禁用,我无法调整屏幕大小.如何启用它在全屏和后退之间切换?谢谢

I am new to Python programming and I recently started working with the PyGame module. Here is a simple piece of code to initialize a display screen. My question is : Currently, the maximize button is disabled and I cannot resize the screen. How do I enable it to switch between full screen and back? Thanks

import pygame, sys
from pygame.locals import *

pygame.init()

#Create a displace surface object
DISPLAYSURF = pygame.display.set_mode((400, 300))

mainLoop = True

while mainLoop:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            mainLoop = False
    pygame.display.update()

pygame.quit()

推荐答案

要以原始分辨率全屏显示,请执行

To become fullscreen at native resolution, do

DISPLAYSURF = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)

要使窗口可调整大小,请在设置模式时添加 pygame.RESIZABLE 参数.您可以多次设置屏幕表面的模式,但您可能必须执行 pygame.display.quit()pygame.display.init()

To make the window resizeable, add the pygame.RESIZABLE parameter when seting the mode. You can set the mode of the screen surface multiple times but you might have to do pygame.display.quit() followed by pygame.display.init()

您还应该在此处查看 pygame 文档http://www.pygame.org/docs/ref/display.html#pygame.display.set_mode

You should also check the pygame documentation here http://www.pygame.org/docs/ref/display.html#pygame.display.set_mode

这篇关于如何在 PyGame 中最大化显示屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆