什么时候需要 pygame.init()? [英] When is pygame.init() needed?

查看:125
本文介绍了什么时候需要 pygame.init()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 pygame,并且在绝大多数教程中都说在做任何事情之前应该运行 pygame.init().我正在做一个特定的教程并像以前一样输入代码,并注意到在一个又一个示例中没有 pygame.init() 并且没有任何模块的其他显式初始化.

I am studying pygame and in the vast majority of tutorials it is said that one should run pygame.init() before doing anything. I was doing one particular tutorial and typing out the code as one does and noticed that in example after example there is no pygame.init() and no other explicit initialisation of any modules.

例如,以下工作(至少对我而言)没有任何问题:

For instance, the following works (for me, at least) without any issues:

import pygame

screen = pygame.display.set_mode((600, 400))

while True:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            raise SystemExit

只是想知道如何准确找出在 pygame.init() 运行时初始化的内容以及未运行 pygame.init() 时初始化的内容.

Just wondering how to find out exactly what is initialised when pygame.init() is run and what is initialised when pygame.init() is not run.

推荐答案

这将尝试为您初始化所有 pygame 模块.不是所有 pygame 模块都需要初始化,但这会自动初始化那些.

This will attempt to initialize all the pygame modules for you. Not all pygame modules need to be initialized, but this will automatically initialize the ones that do.

http://www.pygame.org/docs/tut/ImportInit.html

我不知道必须初始化哪些模块,但看起来 displayevent 不属于该类别.我只是建议你这样做,因为也许有些模块可以在没有初始化的情况下工作,但不会以同样的方式工作,或者他们会错过一些重要的东西.

I don't know what modules must be initialized, but it looks like display and event aren't in that category. I just recommend you to do it, because maybe some modules can work without being initialized but won't work the same way or they'll miss something important.

这篇关于什么时候需要 pygame.init()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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