title: Supposed to be global Tkinter-window 'not defined'
body: <p>I have written a little tool that simulates a traffic light system with a GUI. Worked fine on Windows with Python 2.7, but since it was intended to run on a Raspberry Pi where it was necessary to re-write the threading-part.</p>
  
  <p>So I am trying to put most of the stuff into one method. But still I am not able to create a Tkinter-element from outside the method where the Tkinter-window was built. Can someone tell me how to fix the code so that it is possible to create elements from another methode? Here's the code:</p>
  
  <pre><code>class GUI (threading.Thread):
  
      def __init__(self):
          threading.Thread.__init__(self)
  
      def run(self):
          global window
          window = Tk()
          window.title('Ampel GUI')
          window = Canvas(window, width=400, height=200)
          window.pack()
  
          button1 = Button(window, text="Press", command=lambda: pushbutton(25))
          button1.pack()
          button1.place(x=190, y=70)
  
          button2 = Button(window, text="Press", command=lambda: pushbutton(12))
          button2.pack()
          button2.place(x=115, y=160)
  
          (...)
  
          window.mainloop()
  
      @staticmethod
      def output(lampe, status):
          if status == 0:
              if lampe == 21:
                  window.create_oval(140, 30, 160, 10, fill="#FFA6A6")
  
              if lampe == 20:
                  window.create_oval(170, 30, 190, 10, fill="#FAFAAA")
  
      (...)
  
  output(20,0)
  </code></pre>
  
  <p>and this is what I get:</p>
  
  <pre><code>line 120, in output
  window.create_oval(170, 30, 190, 10, fill="#FAFAAA")
  NameError: global name 'window' is not defined
  </code></pre>
  
  <p>What should I do to create the oval as intended?</p>