# Splitting Pygame functionality between classes or modules?

I am attempting to make my pygame application more modular so that different functionalities are split up into different classes and modules. I am having some trouble getting pygame to allow me to draw or load images in secondary classes when the display has been set and pygame.init() has been done in my main class.

I have typically used C# and XNA to accomplish this sort of behavior, but this time I need to use python.

How do I init Pygame in class1, then create an instance of class2 which loads and converts() images.

I have tried pygame.init() in class 2 but then it tells me no display mode has been set, when it has been set in class1. I am under the impression I do not want to create multiple Pygame displays as that gets problematic.

I am probably missing something pythonic and simple but I am not sure what. How do I create a Display class, init Python and then have other modules do my work like loading images, fonts etc.?

Here is the simplest version of what I am doing:

class1:
def __init__(self):
self.screen = pygame.display.set_mode((600,400))

class2:
def __init__(self):
self.images = ['list of images']

self.images = os.listdir('./images/') #get all images in the images directory
for img in self.images:
scale_img = pygame.transform.scale(new_img, (pygame.display.Info().current_w, pygame.display.Info().current_h))
self.images.append(scale_img)

if __name__ == "__main__":
c1 = class1()


Of course when it tries to load an convert the images it tells me Pygame has not been initialized, so I throw in a pygame.init() in class2 (I have heard it is safe to init multiple times) and then the error goes to:

pygame.error: No video mode has been set

1. pygame.init() - this needs to happen before any other use of pygame
2. pygame.display.set_mode() - this needs to be done before any other use of pygame.display
3. Load and scale your images. Note that pygame.image.load() doesn't need pygame.display.set_mode(), but you're also using pygame.display.Info() to scale your images, hence the order.