【问题标题】:How do I maximize the display screen in PyGame?如何在 PyGame 中最大化显示屏幕?
【发布时间】:2015-07-21 12:02:24
【问题描述】:

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

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

【问题讨论】:

    标签: python pygame


    【解决方案1】:

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

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

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

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

    【讨论】:

      【解决方案2】:

      你要找的方法是pygame.display.toggle_fullscreen

      或者,按照指南在大多数情况下的建议,拨打pygame.display.set_mode() with the FULLSCREEN tag

      在你的情况下,这看起来像

      DISPLAYSURF = pygame.display.set_mode((400, 300), pygame.FULLSCREEN)
      

      (请使用pygame.FULLSCREEN 而不是只使用FULLSCREEN,因为在使用我自己的系统进行测试时FULLSCREEN 只是在不适合分辨率的情况下最大化了窗口,而pygame.FULLSCREEN 适合我的分辨率以及最大化。)

      【讨论】:

        【解决方案3】:

        这会让你从最大化切换到初始大小

        import pygame, sys
        from pygame.locals import *
        
        pygame.init()
        
        #Create a displace surface object
        #Below line will let you toggle from maximize to the initial size
        DISPLAYSURF = pygame.display.set_mode((400, 300), RESIZABLE)
        
        mainLoop = True
        
        while mainLoop:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    mainLoop = False
            pygame.display.update()
        
        pygame.quit()
        

        【讨论】:

          【解决方案4】:
          import pygame, os
          
          os.environ['SDL_VIDEO_CENTERED'] = '1' # You have to call this before pygame.init()
          
          pygame.init()
          
          info = pygame.display.Info() # You have to call this before pygame.display.set_mode()
          screen_width,screen_height = info.current_w,info.current_h
          

          这些是您的屏幕/显示器的尺寸。您可以使用这些或缩小它们以排除边框和标题栏:

          window_width,window_height = screen_width-10,screen_height-50
          window = pygame.display.set_mode((window_width,window_height))
          pygame.display.update()
          

          【讨论】:

            【解决方案5】:

            您必须像这样将全屏参数添加到显示声明中:

            import pygame, sys
            from pygame.locals import *
            
            pygame.init()
            
            #Create a displace surface object
            DISPLAYSURF = pygame.display.set_mode((400, 300), FULLSCREEN)
            
            mainLoop = True
            
            while mainLoop:
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        mainLoop = False
                pygame.display.update()
            
            pygame.quit()
            

            【讨论】:

            • 如何退出全屏绘图?
            猜你喜欢
            • 2017-09-12
            • 2017-02-16
            • 2018-05-18
            • 1970-01-01
            • 2011-03-22
            • 1970-01-01
            • 2020-04-19
            • 1970-01-01
            相关资源
            最近更新 更多