0

I want to save the output of the following Tkinter application as an Image (png or jpg).

Here is the application snippet,

#Import the required libraries
from tkinter import *

#Create an instance of Tkinter Frame
root= Tk()
root.geometry("700x350")
canvas= Canvas(root, width= 500, height= 350)
canvas.pack()
canvas.create_rectangle(100,100,300,300, outline= 'red')
root.mainloop()

The Output of the following Code is which I want to save as png or jpg.

enter image description here

  • 3
    Does this answer your question? [How to do a screenshot of a tkinter application?](https://stackoverflow.com/questions/19964345/how-to-do-a-screenshot-of-a-tkinter-application) – CoolCoder May 24 '21 at 06:27
  • If you really want to draw a red rectangle on a white background and save as a PNG, you'd be better off with **ImageMagick**. – Mark Setchell May 24 '21 at 06:29
  • Mark, I don't want to draw a rectangle specifically or any related canvas figure. I just want to save the Output Image that can be anything in the Tkinter window. – codewithdev May 24 '21 at 06:34
  • You can also do screenshots using the `PIL.ImageGrab` module — see [this answer](https://stackoverflow.com/a/38645917/355230). Before asking questions here, you can save yourself (and others) some time, by first searching for any existing ones on the same topic *before* asking a new question. – martineau May 24 '21 at 07:17

0 Answers0