title: Moving Around A Python Canvas Without Using Scrollbars
body: <p><strong>Background:</strong><br>I have a program using Tkinter as the basis of the GUI. The program has a canvas which is populated with a large number of objects. Currently, in order to move all objects on the screen, I am simply binding a movement function to the tag 'all' which of course moves all objects on the screen. However, it is vital for me to keep track of <em>all</em> canvas object positions- i.e. after every move I log the new position, which seems unnecessarily complicated.</p>
  
  <p><strong>Question:</strong><br>
  What is the best way to effectively scroll/drag around the whole canvas (several times the size of the screen) using only the mouse (not using scrollbars)?</p>
  
  <p><strong>My Attempts:</strong><br>I have implemented scrollbars and found several guides to setting up scrollbars, but none that deal with this particular requirement.</p>
  
  <p><strong>Example of disused scrollbar method:</strong></p>
  
  <pre><code>from Tkinter import *
  
  class Canvas_On:    
      def __init__(self, master):
  
          self.master=master
          self.master.title( "Example")
          self.c=Canvas(self.master, width=find_res_width-20, height=find_res_height, bg='black', scrollregion=(0,0,5000,5000))
          self.c.grid(row=0, rowspan=25, column=0)
          self.c.tag_bind('bg', '&lt;Control-Button-1&gt;', self.click)
          self.c.tag_bind('bg', '&lt;Control-B1-Motion&gt;', self.drag)
  
          self.c.tag_bind('dot', '&lt;Button-1&gt;', self.click_item)
          self.c.tag_bind('dot', '&lt;B1-Motion&gt;', self.drag_item)
  
          draw=Drawing_Utility(self.c)
          draw.drawer(self.c)
  
      def click(self, event):
          self.c.scan_mark(event.x, event.y)
  
      def drag(self, event):
          self.c.scan_dragto(event.x, event.y)
  
      def click_item(self, event):
          self.c.itemconfigure('dot 1 text', text=(event.x, event.y))
          self.drag_item = self.c.find_closest(event.x, event.y)
          self.drag_x, self.drag_y = event.x, event.y
          self.c.tag_raise('dot')
          self.c.tag_raise('dot 1 text')
  
      def drag_item(self, event):
          self.c.move(self.drag_item, event.x-self.drag_x, event.y-self.drag_y)
          self.drag_x, self.drag_y = event.x, event.y
  
  class Drawing_Utility:
      def __init__(self, canvas):
          self.canvas=canvas
          self.canvas.focus_set()
  
  
      def drawer(self, canvas):
          self.canvas.create_rectangle(0, 0, 5000, 5000, 
                              fill='black', tags='bg')
          self.canvas.create_text(450,450, text='', fill='black', activefill='red', tags=('draggable', 'dot', 'dot 1 text'))
          self.canvas.create_oval(400,400,500,500, fill='orange', activefill='red', tags=('draggable', 'dot', 'dot 2'))
          self.canvas.tag_raise(("dot"))
  
  root=Tk()
  find_res_width=root.winfo_screenwidth()
  find_res_height=root.winfo_screenheight()
  run_it=Canvas_On(root)  
  root.mainloop() 
  </code></pre>
  
  <p><strong>My Particular Issue</strong><br><br>
  My program generates all canvas object coordinates and then draws them. The objects are arranged in various patterns, but critically they must 'know' where each other is. When moving around the canvas using the method @abarnert kindly supplied, and a similar method I wrote that moved all canvas objects, the issue arises that each object 'thinks' it is at the canvas coordinates generated before the objects were drawn. For example if I drag the canvas 50 pixels to the left and clicked on an object in my program, it jumps 50 pixels back to the right to it's original position. My solution to this was to write some code that, upon release of the mouse button, logged the last position and updated the coordinate data of each object. However, I'm looking for a way to remove this last step- I was hoping there was a way to move the canvas such that the object positions were absolute, and assumed a function similar to a 'scroll' function would do this. I realise I've rambled here, but I've added a couple of lines to the example above which highlights my issue- by moving the canvas you can see that the coordinates change. Thank you again.</p>