I am trying to save a tkinter screen to a file (to later convert into a video).
I can't get the correct position of the canvas for using ImageGrab.
My relevant imports are:
import tkinter
import pyscreenshot as ImageGrab
I am trying to save the screen using (after drawing the screen):
grab = ImageGrab.grab(bbox=canvas.bbox())
ImageGrab.grab_to_file(fileName,grab)
I don't know how to get the canvas position for using "ImageGrab.grab".
Is there any way to get the bounding box for the whole canvas, so as to later use ImageGrab to store a screenshot?
---Edit------------------------------------------------------------------
Solution:
box = (canvas.winfo_rootx(),canvas.winfo_rooty(),canvas.winfo_rootx()+canvas.winfo_width(),canvas.winfo_rooty() + canvas.winfo_height())
grab = ImageGrab.grab(bbox = box)
grab.save(file_path)
You have methods like
winfo_x(),winfo_y()to get position inside parent widget (it doesn't have to be main window), andwinfo_rootx(),winfo_rooty()to get position on screen.Effbot.org: Basic Widget Methods
Code displays canvas' position on screen and inside parent
FrameExample result