title: Tkinter: Scaling items on a canvas
body: <p>I was trying to understand how the scaling of canvas works.</p>
  
  <p>Take for example, the following code. Why is that <code>canvas.scale("all", ...)</code>, which is bind to mouse wheel, is scaling all the rectangles and not the text as well.</p>
  
  <p>How can I achieve scaling of text along with the rectangles?</p>
  
  <pre><code>import Tkinter as tk
  import random
  
  pressed = False
  
  class Example(tk.Frame):
      def __init__(self, root):
          tk.Frame.__init__(self, root)
          self.canvas = tk.Canvas(self, width=400, height=400, background="bisque")
          self.xsb = tk.Scrollbar(self, orient="horizontal", command=self.canvas.xview)
          self.ysb = tk.Scrollbar(self, orient="vertical", command=self.canvas.yview)
          self.canvas.configure(yscrollcommand=self.ysb.set, xscrollcommand=self.xsb.set)
          self.canvas.configure(scrollregion=(0,0,1000,1000))
  
          self.xsb.grid(row=1, column=0, sticky="ew")
          self.ysb.grid(row=0, column=1, sticky="ns")
          self.canvas.grid(row=0, column=0, sticky="nsew")
          self.grid_rowconfigure(0, weight=1)
          self.grid_columnconfigure(0, weight=1)
  
          #Plot some rectangles
          for n in range(50):
              x0 = random.randint(0, 900)
              y0 = random.randint(50, 900)
              x1 = x0 + random.randint(50, 100)
              y1 = y0 + random.randint(50,100)
              color = ("red", "orange", "yellow", "green", "blue")[random.randint(0,4)]
              self.canvas.create_rectangle(x0,y0,x1,y1, outline="black", fill=color, activefill="black", tags=n)
          self.canvas.create_text(50,10, anchor="nw", text="Click and drag to move the canvas\nScroll to zoom.")
  
          # This is what enables using the mouse:
          self.canvas.bind("&lt;ButtonPress-1&gt;", self.move_start)
          self.canvas.bind("&lt;B1-Motion&gt;", self.move_move)
  
          self.canvas.bind("&lt;ButtonPress-2&gt;", self.pressed2)
          self.canvas.bind("&lt;Motion&gt;", self.move_move2)
  
          #linux scroll
          self.canvas.bind("&lt;Button-4&gt;", self.zoomerP)
          self.canvas.bind("&lt;Button-5&gt;", self.zoomerM)
          #windows scroll
          self.canvas.bind("&lt;MouseWheel&gt;",self.zoomer)
          # Hack to make zoom work on Windows
          root.bind_all("&lt;MouseWheel&gt;",self.zoomer)
  
      #move
      def move_start(self, event):
          self.canvas.scan_mark(event.x, event.y)
      def move_move(self, event):
          self.canvas.scan_dragto(event.x, event.y, gain=1)
  
      #move
      def pressed2(self, event):
          global pressed
          pressed = not pressed
          self.canvas.scan_mark(event.x, event.y)
      def move_move2(self, event):
          if pressed:   
              self.canvas.scan_dragto(event.x, event.y, gain=1)        
  
      #windows zoom
      def zoomer(self,event):
          if (event.delta &gt; 0):
              self.canvas.scale("all", event.x, event.y, 1.1, 1.1)
          elif (event.delta &lt; 0):
              self.canvas.scale("all", event.x, event.y, 0.9, 0.9)
          self.canvas.configure(scrollregion = self.canvas.bbox("all"))
  
      #linux zoom
      def zoomerP(self,event):
          self.canvas.scale("all", event.x, event.y, 1.1, 1.1)
          self.canvas.configure(scrollregion = self.canvas.bbox("all"))
      def zoomerM(self,event):
          self.canvas.scale("all", event.x, event.y, 0.9, 0.9)
          self.canvas.configure(scrollregion = self.canvas.bbox("all"))
  
  if __name__ == "__main__":
      root = tk.Tk()
      Example(root).pack(fill="both", expand=True)
      root.mainloop()
  </code></pre>