首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有标题栏(和按钮)的PyGame全屏

带有标题栏(和按钮)的PyGame全屏
EN

Stack Overflow用户
提问于 2019-06-23 09:36:45
回答 1查看 511关注 0票数 1

我正在尝试让我的PyGame窗口全屏显示,但我希望有按钮来关闭程序,并最小化窗口。如果这在PyGame中是可能的,请告诉我如何实现。提前谢谢你!

EN

回答 1

Stack Overflow用户

发布于 2019-06-23 12:41:54

是。您可以在运行时更改pygame.display.set_mode,也可以使用pygame.event检查退出。

示例代码:

代码语言:javascript
复制
import pygame,sys
pygame.init()
screen = pygame.display.set_mode((1440,900),pygame.FULLSCREEN,32) #Fullscreen - my display is 1440 by 900
pygame.display.set_caption("Example")
cursor_x,cursor_y = 0,0
cmddown = False
fullscreen = True
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.KEYDOWN:
            #Toggle Fullscreen (press escape to exit/enter fullscreen)
            if event.key == pygame.K_ESCAPE:
                if fullscreen == True:
                    screen = pygame.display.set_mode((1440,900)) #exits fullscreen
                    pygame.display.set_caption("Example")
                    fullscreen = False
                else:
                    screen = pygame.display.set_mode((1440,900),pygame.FULLSCREEN,32)
                    pygame.display.set_caption("Example")
                    fullscreen = True
            #Check Command + Q
            if event.key == pygame.K_LMETA:
                cmddown = True
            if event.key == pygame.K_q:
                if cmddown == True:
                    pygame.quit()
                    sys.exit()
        elif event.type == pygame.KEYUP:
            cmddown = False
    screen.fill((0,0,0))
    pygame.display.flip()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56720405

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档