0
x = self.canvas.winfo_rootx() + self.canvas.winfo_x()
y = self.canvas.winfo_rooty() + self.canvas.winfo_y()
x1 = x + self.canvas.winfo_width()
y1 = y + self.canvas.winfo_height()
ImageGrab.grab().crop((x, y, x1, y1)).save(filename)

I am using this method but it does not capture the whole canvas screen

it is saving like this

and if i move the root window, the image it captures also changes.

Sidhant
  • 9
  • 2
  • 1
    Does this answer your question? [How can I convert canvas content to an image?](https://stackoverflow.com/questions/9886274/how-can-i-convert-canvas-content-to-an-image) – TheLizzard Apr 03 '21 at 13:38
  • no it isnt working for me – Sidhant Apr 03 '21 at 15:41
  • Are you getting an error? When you tried it does it save to the file? When I tried it (a while ago) I also had trouble setting it up. Did you try `AndyRichter`'s answer (from [here](https://stackoverflow.com/a/55385764/11106801))? – TheLizzard Apr 03 '21 at 15:43
  • OSError: Unable to locate Ghostscript on paths. This error shows up – Sidhant Apr 04 '21 at 12:27
  • Look at [this](https://stackoverflow.com/questions/44587376/oserror-unable-to-locate-ghostscript-on-paths) – TheLizzard Apr 04 '21 at 12:31
  • It still isnt capturing the whole Canvas Widget and it also captures the background of the desktop. the tkinter window looks like this https://imgur.com/a/LGXrvVz and the image grab that happen is https://imgur.com/a/opDvMXD – Sidhant Apr 06 '21 at 15:24
  • When you tried: `.postscript(file="file_name.eps", colormode="color")`, it gave you an `OSError`. Did you try to resolve it? – TheLizzard Apr 06 '21 at 15:45
  • I don't want to save these images so i didn't try it. – Sidhant Apr 06 '21 at 15:54
  • In the code that you showed above you are saving it to file so I don't get what you mean by *"I don't want to save these images"* – TheLizzard Apr 06 '21 at 15:55
  • i am trying to make the handwritten digit recognition application. I am using the tkinter for gpu. In the root window there will be 2 buttons(predict and clear_screen) and Canvas widget (where i draw the numbers). Now if i press the predict button, it will call an function that will grab the whole canvas widget of the root window and will show it on the another window of the opencv (using the imshow method of opencv library) – Sidhant Apr 06 '21 at 16:01
  • So save the contents of the `Canvas` as an image (using `.postscript(file="file_name.eps", colormode="color")`) and then open them using `opencv`. – TheLizzard Apr 06 '21 at 16:04

0 Answers0