title: Image for Canvas is not created
body: <p>So I want a window that updates a shown picture after clicking.
  It works fine as long as there is no further <code>tk.Tk()</code> instance (remove/add line 8 of the code below).</p>
  <p>If one is created before, this error is raised:</p>
  <pre><code>line 29, in CreatePeakSelectionWindow
  [...]
  self.imgCanvas.create_image((0,0),anchor=tk.NW,image=self.img1)
  [...]
  _tkinter.TclError: image &quot;pyimage1&quot; doesn't exist
  </code></pre>
  <p>I think I need to pass some argument to <code>Tk()</code>?
  I don't know where to even look to address this issue and understand how it is caused.
  Sadly this widget is to be used to allow manual selection of some peaks and should be done in an external window.
  FYI all arrays are dummies (random arrays) for simplicities sake.</p>
  <p>Thank you very much for any help!</p>
  <p>The code which causes the issue is the following:</p>
  <pre><code>import tkinter as tk
  import numpy as np
  from PIL import Image,ImageTk
  import matplotlib.pyplot as plt
  
  class Dummy:
      def __init__(self):
          self.MainWin = tk.Tk() #&gt;this line causes the issue
          imgs = np.random.randint(0,255,(512,624,2))
          self.img = imgs[:,:,0] #self.img is a numpy array in black and white
          self.imgSize = self.img.shape
          self.peakList = np.array([[200,200],[300,400]])
          self.selectedIndexOfPeaksList = []
          self.peakListGenerated = True
  
      def CreatePeakSelectionWindow(self):
          if self.peakListGenerated:
              self.selectedIndexOfPeaksList = []
              self.PeakSelectionWindow = tk.Tk()
              self.PeakSelectionWindow.protocol(&quot;WM_DELETE_WINDOW&quot;,self.PeakSelectionWindowClose)
              self.PeakSelectionWindow.geometry(&quot;%sx%s&quot;%(self.imgSize[1],self.imgSize[0]))
              self.PeakSelectionWindow.title(&quot;Peak Slection&quot;)
              self.img1 = ImageTk.PhotoImage(image=Image.fromarray(self.img))
              self.imgCanvas = tk.Canvas(self.PeakSelectionWindow,width=self.imgSize[1],height=self.imgSize[0])
              self.imgCanvas.place(x=0,y=0)
              self.PeakSelectionWindow.bind(&quot;&lt;Button 1&gt;&quot;,self.LeftClick)
              self.PeakSelectionWindow.bind(&quot;&lt;Button 3&gt;&quot;,self.RightClick)
              self.PeakSelectionWindow.update()
              self.imgCanvas.create_image((0,0),anchor=tk.NW,image=self.img1)
          else:
              print(&quot;List of peaks has not yet been generated!&quot;,file=sys.stderr)
  
      def PeakSelectionWindowClose (self):
          if len(self.selectedIndexOfPeaksList) &gt; 0:
              print(&quot;put extraction here&quot;)
              #self.selectedPeaksEntry.insert(tk.END,&quot;, &quot;.join(map(str,self.selectedIndexOfPeaksList)))
          self.PeakSelectionWindow.destroy()
  
      def LeftClick(self,event):
          distance = np.sqrt((self.peakList[:,1]-event.x)**2+(self.peakList[:,0]-event.y)**2)
          index = np.argmin(distance)
          if index not in self.selectedIndexOfPeaksList:
              self.peakList[index]
              self.selectedIndexOfPeaksList += [index]
              newImg = np.random.randint(0,255,(self.img.shape[0],self.img.shape[1],3))
              self.PeakSelectionWindow.newImg = img = ImageTk.PhotoImage(image=Image.fromarray(newImg.astype(&quot;uint8&quot;),mode=&quot;RGB&quot;))
              self.imgCanvas.delete(&quot;all&quot;)
              self.imgCanvas.create_image((0,0),anchor=tk.NW,image=self.PeakSelectionWindow.newImg)
              self.imgCanvas.update()
  
      def RightClick (self,event):
          distance = np.sqrt((self.peakList[:,1]-event.x)**2+(self.peakList[:,0]-event.y)**2)
          index = np.argmin(distance)
          print(self.selectedIndexOfPeaksList)
          if index in self.selectedIndexOfPeaksList:
              if len(self.selectedIndexOfPeaksList) &gt; 1:
                  self.selectedIndexOfPeaksList.remove(index)
                  newImg = np.random.randint(0,255,(self.img.shape[0],self.img.shape[1],3))
                  self.PeakSelectionWindow.newImg = img = ImageTk.PhotoImage(image=Image.fromarray(newImg.astype(&quot;uint8&quot;),mode=&quot;RGB&quot;))
                  self.imgCanvas.delete(&quot;all&quot;)
                  self.imgCanvas.create_image((0,0),anchor=tk.NW,image=self.PeakSelectionWindow.newImg)
                  self.imgCanvas.update()
              else:
                  self.selectedIndexOfPeaksList = []
                  self.PeakSelectionWindow.newImg = newImg = ImageTk.PhotoImage(image=Image.fromarray(self.img.astype(&quot;uint8&quot;)))
                  self.imgCanvas.delete(&quot;all&quot;)
                  self.imgCanvas.create_image((0,0),anchor=tk.NW,image=self.PeakSelectionWindow.newImg)
                  self.imgCanvas.update()
  
  
  
  
  if __name__ == &quot;__main__&quot;:
      window = Dummy()
      window.CreatePeakSelectionWindow()
      tk.mainloop()
  </code></pre>