473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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 2996
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

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

Similar topics

1
by: Peter Otten | last post by:
Before I start moving them into dark corners of the canvas - is there a way to hide/show Tkinter canvas items without having to maintain their original position externally? All I've found so far is...
1
by: Elaine Jackson | last post by:
Newbie. Playing with the 'turtle' module and wondering if there's a way to save the graphics you make with it. The documentation itself has nothing to say about this, nor (as far as I can tell)...
1
by: Erik Johnson | last post by:
I want to draw some simple (dynamic) graphs and get these saved as a JPEG file to reference in a web link. I am aware of PIL (Python Image Library), but unfortunatley my system does not have it...
0
by: Shi Mu | last post by:
got confused by x, y coordinates in Tkinter canvas. from left to right, does X increase? from top to bottom, does y increase?
3
by: Tuvas | last post by:
I'm trying to display a picture on a Tkinter Canvas. It seems to work fine the first time that it is displayed. However, subsequent times running shows an error like this: TCLerror: Wrong #...
5
by: Dean Allen Provins | last post by:
I need to determine the size of a canvas while the process is running. Does anyone know of a technique that will let me do that? Thanks, Dean
0
by: fxe | last post by:
Hi, I am using tkinter and I have a canvas that with several rectangles drawn on it. The rectangles need to have bindings to move and resize them. No problem here, but I also need to display a...
0
by: WaterWalk | last post by:
Hello. When I tried to make Tkinter canvas widget respond to MouseWheel event on Windows XP, I failed. The canvas just doesn't receive MouseWheel event. I used bind_all to find out which widget...
4
by: skanemupp | last post by:
mapq = PhotoImage(file = 'C:\Users\saftarn\Desktop\elmapovic.gif') w.create_image(10, 10, image = mapq, anchor = NW) after doing this is there any possibility of getting the characteristics of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.