954,546 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to create a .jpg file with a drawing in Tkinter ?

Hello,

I would like to save the drawings I have made on a Canvas with the Tkinter Module.

Is it possible to make a .jpg or .gif or .bmp from a Tkinter window ?

Thank you!

Lapinbriac
Newbie Poster
4 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

Ok i've found the response on www.developpez.net
It uses the .postscript method from canvas and the ImageGrab module

Bonjour,
Il y a la méthode '.postscript', qui génère ... du postscript.
Sous MS windows, tu peux utiliser ImageGrab (PIL). Je ne crois pas que cela fonctionne sous Linux.
x = canvas.winfo_rootx()
y = canvas.winfo_rooty()
w = canvas.winfo_width()
h = canvas.winfo_height()
img= ImageGrab.grab((x+2, y+2, x+w-2, y+h-2)).save("tmp.bmp")

Lapinbriac
Newbie Poster
4 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

It would be simple to use the capture option that comes with many image viewers like XnView (nice and free).

For another potential solution look at:
http://www.daniweb.com/code/snippet705.html

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You