Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Tkinter - save canvas - tkinter crashes

I'm trying to save my canvas using the postscript method, and Tkinter crashes...

w.postscript(file="my_drawing.ps", colormode='color')

gets the exception:

w.postscript(file="my_drawing.ps", colormode='color')
File "C:\python27\lib\lib-tk\Tkinter.py", line 2307, in postscript
self._options(cnf, kw))
_tkinter.TclError: invalid command name ".57816328L"

I'm not sure what this error means - has anyone encountered that before?

I tried without the color option too, with no avail.


Edit - widgit stripped down to basics gives same error:

from Tkinter import *
master = Tk()
w = Canvas(master, width=1000, height=1000)
w.pack()
w.create_oval(450,550,550,450)
mainloop()
w.postscript(file="my_drawing.ps")
like image 759
Jay Gattuso Avatar asked Apr 14 '26 23:04

Jay Gattuso


1 Answers

It seems to work if you simply move the w.postscript() call above the mainloop() call. This means that the error is due to calling w.postscript() after the Tkinter GUI is closed (since mainloop() runs until the window is closed).

I noticed this was a difference between your code and this example, so I tried it and saw that the .ps file was created as soon as the script is ran.

like image 130
gary Avatar answered Apr 17 '26 12:04

gary



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!