简体   繁体   English

Python ImageGrab无法与输入配合使用

[英]Python ImageGrab Not Working With Input

In my program, I'm taking a screenshot of a part of my screen, which works. 在我的程序中,我正在截取屏幕一部分的屏幕截图,该屏幕截图可以正常工作。 But when I add anything in front of calling the function it's in, it no longer gets past the ImageGrab part. 但是,当我在调用该函数之前添加任何内容时,它将不再超出ImageGrab部分。

This works: 这有效:

def takePictures():
    print("3")
    if __name__ == '__main__':
        print("1")
        im = ImageGrab.grab(bbox=(760, 250, 1160, 680))  # X1,Y1,X2,Y2
        print("2")
        im.save('ALL.png')
        #im.show()
 takePictures()

This doesn't: 这不是:

def takePictures():
    print("3")
    if __name__ == '__main__':
        print("1")
        im = ImageGrab.grab(bbox=(760, 250, 1160, 680))  # X1,Y1,X2,Y2
        #^^^ Doesnt get past this line
        print("2")
        im.save('ALL.png')
        #im.show()
if input() == "":
    takePictures()

I've also tried it with inputs from keys on a different window and it's the same. 我也尝试过使用来自不同窗口的键的输入,它是相同的。

Your program will pause at 您的程序将在

if input() == "":
    takePictures()

until you activate the python executing window and hit the enter key. 直到您激活python执行窗口并按下Enter键。

If you want to take screen shots, you can use, say 如果您想拍摄屏幕截图,可以说

time.sleep(10)

giving yourself 10 seconds to activate the window you want to take a screen shot of. 给自己10秒的时间来激活您要为其截屏的窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM