Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I would like to do a screenshot with
lackey
of ideally the screen of an app (but to begin with, a screenshot of the whole screen would be OK).
I have tried
from lackey import *
notepad = App('notepad.exe')
notepad.open()
focusWindow = notepad.focusedWindow()
s = Screen(0)
r = s.capture()
with open("toto.bmp", "wb") as f:
f.write(r)
The picture cannot be open because the function capture
returns a numpy.ndarray
.
I also tried to do the following but the result is the same:
r = Screen.capture(focusWindow)
Anyone knows how to do a screenshot?
Thanks
You can use the Image.fromarray and Image.save methods from the PIL library to save the image. For some reason the code below captures the window running the script as well as the notepad app, sp I guess you might have to tweak it.
from lackey import *
from PIL import Image
notepad = App('notepad.exe')
notepad.open()
focusWindow = notepad.focusedWindow()
sleep(5) # allow some time for the notepad window to appear before capture.
screen = Screen()
capture = screen.capture(focusWindow)
image = Image.fromarray(capture)
image.save("test.bmp")
notepad.close()
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.