Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Grab and save a scrollable canvas including the invisible part #8680

Answered by radarhere
AdrianPhil asked this question in Q&A
Discussion options

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

You must be logged in to vote

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

Comment options

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.

You must be logged in to vote
1 reply
Comment options

That is a great clarification.
Clearly not ideal so I should look for printing alternatives as scrolling will not create a great UI experience.

Answer selected by AdrianPhil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /