title: Using classes in Pygame
body: <p>Okay, so I am starting to have fun with pygame. But I've got a problem. I tried to somehow enchance my code, make it organised, so I've decided to use classes here. It looks like this:</p>
  
  <pre><code>import pygame
  from pygame.locals import *
  import sys
  
  pygame.init()
  
  class MainWindow:
      def __init__(self, width, height):
          self.width=width
          self.height=height
          self.display=pygame.display.set_mode((self.width,self.height))
          pygame.display.set_caption("Caption")
      def background(self)
          img = pygame.image.load("image.png")
          self.display.blit(img, (0,0))            
  
  mainWindow = MainWindow(800,600)
  
  while True:
      for event in pygame.event.get():
          if event.type == QUIT:
              pygame.exit()
              sys.exit()
          mainWindow.background()
      pygame.display.update()
  </code></pre>
  
  <p>Okay, works. But what if I want to, for example fill the windows with white color? Then I have to define a method <code>fill()</code>, which will just <code>self.display.fill()</code>, right? Is there a way, to handle it normally, without defining hundreds of pygame-already-existing methods in my class?</p>
  
  <p>And one another thing. If I do something by using my class, and I screw up, I always get this msg:</p>
  
  <pre><code>  File "C:/Python35/game.py", line 23, in &lt;module&gt;
      pygame.display.update()
  pygame.error
  </code></pre>
  
  <p>And I actually don't know what the heck is wrong. If I do this normally, without classes, then I get erros such as,  <code>pygame object blabla has no method blablabla</code> or something like that, I just know what's happening. Is there a way to get through this, and find what's going on?</p>
  
  <p>Thanks in advance for your help!</p>