-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Grab and save a scrollable canvas including the invisible part #8680
-
I've been trying to use img = ImageGrab.grab(bbox=(capture_x1, capture_y1, capture_x2, capture_y2)) to capture and save an image of a scrollable canvas built
canvas = tk.Canvas(canvasFrame, bg="lightgray", yscrollincrement=10, xscrollincrement=10) # Create vertical and horizontal scrollbars for the canvas verticalScrollbar = tk.Scrollbar(canvasFrame, orient="vertical", command=canvas.yview) horizontalScrollbar = tk.Scrollbar(canvasFrame, orient="horizontal", command=canvas.xview) canvas.config(yscrollcommand=verticalScrollbar.set, xscrollcommand=horizontalScrollbar.set) # Place the scrollbars around the canvas canvas.grid(row=0, column=0, sticky="nsew") verticalScrollbar.grid(row=0, column=1, sticky="ns") horizontalScrollbar.grid(row=1, column=0, sticky="ew") # Configure the grid to expand the canvas as the window resizes canvasFrame.grid_rowconfigure(0, weight=1) canvasFrame.grid_columnconfigure(0, weight=1)
While I was able to produce a .png file of the visible part of the screen I was not able to produce a capture of the full image.
Is that a limitation of Grab, a bug or is there something more to add to the code?
Thank you, Adrian
Beta Was this translation helpful? Give feedback.
All reactions
ImageGrab.grab() is currently based on capturing what is visible on the screen, yes.
In order do what you're describing - capture content that isn't visible in the window, but comes from part of the canvas hidden by scrollbars - my suggestion would be to programmatically scroll to the different parts of the canvas, take screen grabs of each of them, and then combine the result using Pillow.
Replies: 1 comment 1 reply
-
ImageGrab.grab() is currently based on capturing what is visible on the screen, yes.
In order do what you're describing - capture content that isn't visible in the window, but comes from part of the canvas hidden by scrollbars - my suggestion would be to programmatically scroll to the different parts of the canvas, take screen grabs of each of them, and then combine the result using Pillow.
Beta Was this translation helpful? Give feedback.
All reactions
-
That is a great clarification.
Clearly not ideal so I should look for printing alternatives as scrolling will not create a great UI experience.
Beta Was this translation helpful? Give feedback.