title: Pygame, importing modules
body: <p>I'm making some kind of game, but I only managed to complete the start screen. Now I am trying to make the intro of the first level (so a screen with some explanation and a button to continue). This piece of the program is written in another file so I don't get a file of 1000's of lines.</p>
  
  <p>But now I have a problem. I start my level by using:</p>
  
  <pre><code>import level1 # here is my code of the level
  level1.level(screen) # "level" is the class and screen is used so pygame 
                       # uses the same screen and doesn't start a new one
  </code></pre>
  
  <p>This is the level1.py:</p>
  
  <pre><code>class level():
      def __init__(self,originalscreen):
          screen = originalscreen
          self.levelintro()
  
      def levelintro(self):
          # Setting some variables
          levelintro = True
  
          # Background 
          background = pygame.Surface(screen.get_size()) # Change this
          background = background.convert()
          background.fill((255,0,0))
  
          # "Got it" button
          gotitbutton = pygbutton.PygButton((350, 450, 300, 40))
  
          while levelintro:
              screen.fill(0)  
              # Blitting
              screen.blit(background, (0,0))
              gotitbutton.draw(screen)
  
              # Refreshing screen
              pygame.display.flip()
  </code></pre>
  
  <p>So now my problem: in my original .py, I imported pygame. But now I tried to import pygame in the level1.py but it doesn't work. How can I import it?</p>
  
  <p>Thx for your help!
  Lukas</p>
  
  <p>ps: sorry for my bad english, I am dutch...</p>
  
  <p>Edit:
  if I put the "import pygame" in front of my class:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\Lukas\Google Drive\Project\0.1\Project.py", line 17, in &lt;module&gt;
      class startscreen():
    File "C:\Users\Lukas\Google Drive\Project\0.1\Project.py", line 51, in startscreen
      level1.level(screen)
    File "C:\Users\Lukas\Google Drive\Project\0.1\level1.py", line 8, in __init__
      self.levelintro()
    File "C:\Users\Lukas\Google Drive\Project\0.1\level1.py", line 15, in levelintro
      background = pygame.Surface(screen.get_size()) # Change this
  NameError: global name 'screen' is not defined
  </code></pre>
  
  <p>I don't understand this, because I called the method "level" with level1.level(screen) so it passes the screen and then it sets screen = originalscreen (witch equals the screen from my original file)</p>
  
  <p>If I put "import pygame" inside my class, I get:</p>
  
  <pre><code>Warning (from warnings module):
    File "C:\Users\Lukas\Google Drive\Project\0.1\level1.py", line 3
      class level():
  SyntaxWarning: import * only allowed at module level
  
  Traceback (most recent call last):
    File "C:\Users\Lukas\Google Drive\Project\0.1\Project.py", line 17, in &lt;module&gt;
      class startscreen():
    File "C:\Users\Lukas\Google Drive\Project\0.1\Project.py", line 51, in startscreen
      level1.level(screen)
    File "C:\Users\Lukas\Google Drive\Project\0.1\level1.py", line 9, in __init__
      self.levelintro()
    File "C:\Users\Lukas\Google Drive\Project\0.1\level1.py", line 16, in levelintro
      background = pygame.Surface(screen.get_size()) # Change this
  NameError: global name 'pygame' is not defined
  &gt;&gt;&gt; 
  </code></pre>