How to screenshot the entire tkinter canvas as png or pdf How to screenshot the entire tkinter canvas as png or pdf tkinter tkinter

How to screenshot the entire tkinter canvas as png or pdf


The problem you are having is the way you pass canvas to bbox. grab() need to take a tuple of coords and not an object like canvas.

Try this instead:

Delete this after the update() call:

grabcanvas=ImageGrab.grab(bbox=canvas).save("test.png")ttk.grabcanvas.save("test.png")

Then add this after the update() call:

def save_canvas():    x = root.winfo_rootx() + canvas.winfo_x()    y = root.winfo_rooty() + canvas.winfo_y()    xx = x + canvas.winfo_width()    yy = y + canvas.winfo_height()    ImageGrab.grab(bbox=(x, y, xx, yy)).save("test.gif")root.after(1000, save_canvas)