title: PYTHON cannot display image unless I include an erroneous line of code
body: <p>The following code prompts for the filename of an image, and then when the display button is pressed, it displays the image. If the “print(xyz)” line is uncommented, it throws an error that xyz is undefined, but the image does get displayed.  If the line is commented, it of course does not throw an error, but the image does not display.  Any line of code there that throws an error allows the image to be displayed. Any help will be greatly appreciated!</p>
  <p>Wayne</p>
  <pre class="lang-py prettyprint-override"><code>from tkinter import *
  from PIL import ImageTk,Image
  
  def sho_pic():
      fname = image_entry.get()
      photo = Image.open(f&quot;C:\inetpub\wwwroot\web_gift\{fname}&quot;)
      myimage = ImageTk.PhotoImage(photo)
      canvas.create_image(300, 300, image=myimage)
  
      #print(xyz)  &lt;-----------------------
  
  window = Tk()
  window.geometry('800x500')
  canvas = Canvas(window,width=1000, height=1000)
  canvas.pack()
  
  label_image = Label(text=&quot;Image Filename: &quot;)
  label_image.place(x=20,y=20)
  
  image_entry = Entry(width=32)
  image_entry.place(x=150,y=20)
  
  display_button = Button(window, command=sho_pic, text=&quot;Display&quot;)
  display_button.place(x=350,y=20)
  
  window.mainloop()
  </code></pre>