Home > Enterprise >  Why does the Pygame module need to be initialized?
Why does the Pygame module need to be initialized?

Time:06-11

Why does the Pygame module need to be initialized (after importing) so you can properly use it?

Are there any other modules that need to be initialized?

How do you tell if you need to initialize a module or not?

Any answer to any question would be greatly appreciated :)

CodePudding user response:

Pygame is not a module. It is a set of modules. There are multiple modules under Pygame.

What pygame.init() does is to initialize all the modules in Pygame. Alternatively, if you initialize only one of the modules, you could do something like pygame.font.init() to initialize just the font module.

With Pygame, you can initialize all modules. There aren't many.

However, later on, in some cases, the libraries can be massive with a lot more modules, while our project might require only a few. Thus, we would only initialize the modules we need for the project. That is what initialization does, it tells the program what modules to load for us.

CodePudding user response:

I'm not 100% sure, but my guess is that it is not an installed library that the program can access immediately. For example, it's like using a bookstore, and you are reading the history section, but you need to also access the science section, so you call over the science section and then you can read about it. The program needs to be able to read the methods correlating to PyGame, which is some extra extensions that work in Python.

  • Related