By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,985 Members | 1,574 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,985 IT Pros & Developers. It's quick & easy.

Pickle a Tkinter Canvas

P: 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
Share this Question
Share on Google+
1 Reply


bartonc
Expert 5K+
P: 6,596
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.