468,287 Members | 1,977 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,287 developers. It's quick & easy.

Pickle a Tkinter Canvas

7
Hi

Im trying to add save and load functionality to my program and I am using pickle to take the information and dump it in a file. I have been able to pickle everything successfully except for my canvas object which just creates a massive error. My aim is to be able to first pickle the canvas (along with the other data) and subsequently unpickle the canvas with all of the objects which have been placed on it, in the correct place and then replace the canvas in the correct frame. Below is my code for the save and load functions. Any help would be greatly appreciated but please keep it simple, as im still very new

Thanks

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. def _save():
  4.  
  5.     if circuitState.currentFile == "Untitled":
  6.         _saveAs()
  7.         return True
  8.  
  9.     f = open(circuitState.path, 'w')
  10.     pickle.dump([circuitState.all_components, circuitState.all_wires, circuitState.all_hubs, circuitState.all_meters], f)
  11.     f.close() 
  12.  
  13.  
  14. def _saveAs():
  15.  
  16.     circuitState.path = tkFileDialog.asksaveasfilename(title="Save As", defaultextension="cir",
  17.                                filetypes=[('Circuit File','*.cir'),
  18.                                           ('All Files', '*.*')])
  19.  
  20.     changeTitle(circuitState.path)
  21.     _save()
  22.  
  23.  
  24. def _open():
  25.  
  26.     path = tkFileDialog.askopenfilename(title="Open File", defaultextension="cir",
  27.                                filetypes=[('Circuit File','*.cir'),
  28.                                           ('All Files', '*.*')])
  29.  
  30.     f = open(path, 'r')
  31.  
  32.     load = pickle.load(f)
  33.  
  34.     circuitState.all_components = load[0]
  35.     circuitState.all_wires = load[1]
  36.     circuitState.all_hubs = load[2]
  37.     circuitState.all_meters = load[3]
  38.  
  39.     circuitState.path = path
  40.     changeTitle(path)
  41. '    
  42.     f.close()
  43.  
  44.  
May 23 '07 #1
1 2493
bartonc
6,596 Expert 4TB
I'd have a look inside the Turtle Graphics (search turtle in the Manuals) package and see if/how they save the canvas. I'm pretty sure that pickle won't do it.
May 23 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Peter Otten | last post: by
1 post views Thread by Elaine Jackson | last post: by
1 post views Thread by Erik Johnson | last post: by
reply views Thread by Shi Mu | last post: by
3 posts views Thread by Tuvas | last post: by
5 posts views Thread by Dean Allen Provins | last post: by
reply views Thread by fxe | last post: by
reply views Thread by WaterWalk | last post: by
4 posts views Thread by skanemupp | last post: by
2 posts views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.