What exactly does pygame.display.set_mode() do?

空扰寡人 提交于 2021-01-27 04:50:38

问题


I've recently started to play around with the pygame python library and I just wanted to see if I was understanding something correctly:

The following is some code that sets up the window. In the line that says:

windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32)

, does display refer to a module inside of pygame and is set_mode the name of a class in that module? Is this correct?

from pygame.locals import *

# set up pygame
pygame.init()

# set up the window
WINDOWWIDTH = 400
WINDOWHEIGHT = 400
windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32)
pygame.display.set_caption('Animation')

回答1:


display is a module, and set_mode is a function inside that module. It actually creates an instance of the pygame.Surface class, and returns that. See the docs.

In Python, the standard is that classes have capitalised names, and modules and functions are all lower case. Not everything follows that, but a lot of things do, and it looks like pygame is one of them.




回答2:


You are correct that display is a module inside of pygame, but set_mode is not a class, it is a method that initializes a Surface, see the links for more information.



来源:https://stackoverflow.com/questions/6104207/what-exactly-does-pygame-display-set-mode-do

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!