user637965
user637965

Reputation:

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

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

Upvotes: 9

Views: 19072

Answers (2)

Andrew Clark
Andrew Clark

Reputation: 208615

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.

Upvotes: 0

Thomas K
Thomas K

Reputation: 40390

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.

Upvotes: 6

Related Questions