title: How do you permanently alter program data upon execution?
body: <p>I've written a small program which allows me to move a rectangle within a canvas widget. I plan to extend the program to allow me to move other widgets on screen so that I can move things within the window more easily, i.e moving an item via drag n drop, rather than specifying direct coords (at least not explicitly).</p>
  
  <p>Here is the code so far:</p>
  
  <p>from tkinter import *
      root = Tk()</p>
  
  <pre><code>class Move_Shape:
      data = {'x': 0, 'y': 0}
      canvas = Canvas(width = root.winfo_screenwidth(), height = root.winfo_screenheight())
  
  
      def __init__(self, shape, fill = 'White', *coords):
          shape_coords = open('Shape_coords.py', 'r')
          new_coords = shape_coords.readline()[1:-1]
          new_coords = (new_coords).split(',')
  
          if coords != (): new_coords = coords
  
          if shape == 'line': 
              tag = 'line'
              self.canvas.create_line(coords, tags = tag, fill = fill)
  
          elif shape == 'rectangle': 
              tag = 'rect'
              self.canvas.create_rectangle(coords, tags = tag, fill = fill)
          ... More Code
  
  
          self.canvas.tag_bind(tag, '&lt;Button-1&gt;', self.click)
          self.canvas.tag_bind(tag, '&lt;Button1-Motion&gt;', self.track)
          self.canvas.tag_bind(tag, '&lt;ButtonRelease-1&gt;', self.release)
          self.canvas.grid()
  
  
      def click(self, event):
          self.data.update({'x': event.x, 'y': event.y})
          self.item = self.canvas.find_closest(self.data['x'], self.data['y'])
  
      def track(self, event):
          x, y = event.x - self.data['x'], event.y - self.data['y']
          self.canvas.move(self.item, x, y)
          self.data.update({'x': event.x, 'y': event.y})
  
      def release(self, event):
          self.data.update({'x': event.x, 'y': event.y})
          shape_coords = open('shape_coords.py', 'w')
          coords = str(self.canvas.coords(self.item))
          shape_coords.write(coords)
          shape_coords.close()
  
  label = Label(text = 'text more text some more text', fg = 'white', bg = 'white')
  
  Move_Shape('rectangle', 'blue', 50, 50, 200, 200)
  Move_Shape( 'oval', 'green', 50,50,200,200)
  Move_Shape( 'arc', 'red', 50,50,200,200)
  
  
  
  mainloop()
  </code></pre>
  
  <p>So now I can move the rectangle anywhere on screen. However, when I re-open the window, the rectangle starts in it's initial position, which, albeit, was the expected outcome. The desired outcome though it to be able to keep the rectangle where it's at when it's been dropped from where it's dragged. </p>
  
  <p>One such solution I can think of it writing (and rewriting) to another file, so that the new coords rewrites over the original coords within the file, though to me this seems messy, since I have to create a whole new file. Would there be a cleaner, more elegant way to achieve this, or should I go with the idea of appending the new coords to a file?</p>
  
  <p>Thanks in advance for any help!</p>