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 -
-
-
def _save():
-
-
if circuitState.currentFile == "Untitled":
-
_saveAs()
-
return True
-
-
f = open(circuitState.path, 'w')
-
pickle.dump([circuitState.all_components, circuitState.all_wires, circuitState.all_hubs, circuitState.all_meters], f)
-
f.close()
-
-
-
def _saveAs():
-
-
circuitState.path = tkFileDialog.asksaveasfilename(title="Save As", defaultextension="cir",
-
filetypes=[('Circuit File','*.cir'),
-
('All Files', '*.*')])
-
-
changeTitle(circuitState.path)
-
_save()
-
-
-
def _open():
-
-
path = tkFileDialog.askopenfilename(title="Open File", defaultextension="cir",
-
filetypes=[('Circuit File','*.cir'),
-
('All Files', '*.*')])
-
-
f = open(path, 'r')
-
-
load = pickle.load(f)
-
-
circuitState.all_components = load[0]
-
circuitState.all_wires = load[1]
-
circuitState.all_hubs = load[2]
-
circuitState.all_meters = load[3]
-
-
circuitState.path = path
-
changeTitle(path)
-
'
-
f.close()
-
-
1 2996
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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)...
|
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...
|
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?
|
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 #...
|
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
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
| |