【问题标题】:What is the difference between .quit and .QUIT in pygamepygame中的.quit和.QUIT有什么区别
【发布时间】:2021-08-04 03:21:23
【问题描述】:

我只想知道pygame中.quit.QUIT的区别。我对两者都进行了测试,但我仍然不明白它们是如何工作的。

【问题讨论】:

    标签: python pygame


    【解决方案1】:

    QUIT 是事件类型的枚举常量(参见event 模块)。 pygame窗口关闭时发生quit事件:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            # [...]
    

    quit() 是一个取消初始化所有 pygame 模块的函数。这个函数应该在应用程序结束时调用:

    # initialize all imported pygame modules
    pygame.init()
    
    # application loop
    while True:
        # [...]
    
    # uninitialize all pygame modules
    pygame.quit()
    

    【讨论】:

      【解决方案2】:

      pygame 中的 .QUIT 用于检查您是否按下了窗口上的十字按钮,这是一个 pygame 事件。如果你必须退出一个窗口,你应该大部分时间都按十字键。

      这是窗口上带有十字按钮的图像示例

      因此,当您按下窗口上的十字箭头按钮时,它会退出窗口,因此当您按下 pygame 窗口上的十字按钮时,它会存储在名为 pygame.QUIT 的事件中。

      pygame.quit() uninstializez all of pygame's modules 我不确定,但是在你说 pygame.quit() 行之后,你将无法使用大部分或所有 pygame 函数

      【讨论】:

        猜你喜欢
        • 2013-03-30
        • 1970-01-01
        • 2013-02-10
        • 1970-01-01
        • 2014-10-14
        • 2021-06-24
        • 1970-01-01
        • 2021-11-04
        相关资源
        最近更新 更多