How to do a screenshot of a tkinter application?

孤人 提交于 2019-12-01 00:58:21
PurityLake

Since you mentioned that you are on Windows. You can use the Win32 API as directed in this answer Fastest way to take a screenshot with python on windows. Hope this helps.


But actually Pyscreenshot should be what you are looking for.

Take the following code for example:

from pyscreenshot import grab

im = grab(bbox=(100, 200, 300, 400))
im.show()

As you can see you can use bbox to take screenshot that is at co-ordinates (100, 200) and has a width of 300 and a height of 400.

Also as regards the printing check out Printing using win32api. I hope these help.

Using PIL you can do a resize:

from PIL import Image
from pyscreenshot import grab

img = grab(bbox=(100, 200, 300, 400))

# to keep the aspect ratio
w = 300
h = 400
maxheight = 600
maxwidth = 800
ratio = min(maxwidth/width, maxheight/height)
# correct image size is not #oldsize * ratio#

# img.resize(...) returns a resized image and does not effect img unless
# you assign the return value
img = img.resize((h * ratio, width * ratio), Image.ANTIALIAS)

I would advise changing your program so that you can resize the image before printing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!