title: python - A strange problem when I'm trying to display an image in the Toplevel widget
body: <p>I'm using Python(2.5) to make a "web album viewer".</p>
  
  <p>I use Tkinter to write GUI, urllib2 to fetch the image from web, PIL to handle the image</p>
  
  <p>User would click a button, and then it would  create a Toplevel widget, download the picture, and display it in the Toplevel widget.</p>
  
  <p>The button is bound to the "look" method.</p>
  
  <p>So the code is like this:</p>
  
  <pre><code>class App:
  
    #some codes are omitted here
  
    def look(self, pic_url):
      top = Toplevel()
      more = More(top, pic_url)
  
  class More:
    def __init__(self, master, pic_url):
      self.frame = Frame(master)
      self.frame.pack()
      response = urllib2.urlopen(pic_url)
      open("inner_temp.jpg", "wb+").write(response.read())
      self.picture = ImageTk.PhotoImage(file = "inner_temp.jpg")    
      self.photo_label = Label(self.frame, image = self.picture)
      self.photo_label.pack()
  </code></pre>
  
  <p>The Toplevel widget showed, but there's nothing inside. I found "inner_temp.jpg" was downloaded in the folder correctly, but it just didn't show.</p>
  
  <p>But the strangest thing is if I type one whatever character in the end of the code, the console window would show error message, but the picture showed in the Toplevel widget!</p>
  
  <pre><code>  def look(self, pic_url):
      top = Toplevel()
      more = More(top, pic_url)
  
  class More:
    def __init__(self, master, pic_url):
      self.frame = Frame(master)
      self.frame.pack()
      response = urllib2.urlopen(pic_url)
      open("inner_temp.jpg", "wb+").write(response.read())
      self.picture = ImageTk.PhotoImage(file = "inner_temp.jpg")    
      self.photo_label = Label(self.frame, image = self.picture)
      self.photo_label.pack()
      x
  </code></pre>
  
  <blockquote>
    <p>NameError: global name 'x' is not defined</p>
  </blockquote>
  
  <p>How could this happen!? I really can't figure it out!</p>
  
  <p>Can someone help me?</p>
  
  <p>Thanks, and I'm sorry for my poor English.</p>