[英]Timing of ImageGrab.grab() function
I want to take screenshot of my computer.我想为我的电脑截屏。 So I use ImageGrab.grab() function.
所以我使用 ImageGrab.grab() function。
But, when I take screenshot, the timing was little bit fast than what I want.但是,当我截屏时,时间比我想要的要快一点。
As you can see in below picture I use print() function before and after.正如您在下图中看到的,我在前后使用了 print() function。
But the result dosen't show any of those like below.但结果并没有显示任何类似下面的内容。
How can I get the right timing?我怎样才能得到正确的时机?
Thanks for your help!!谢谢你的帮助!!
And I use python 3.6我使用 python 3.6
import numpy as np
from PIL import ImageGrab
import matplotlib.pyplot as plt
if __name__ == "__main__" :
print("want to capture this text")
image = np.array(ImageGrab.grab(bbox=(0, 0, 1920, 1080)))
print("don't want to capture this text")
plt.figure()
plt.imshow(image)
plt.colorbar()
plt.grid(False)
plt.show()
Try to flush the print statement like this:尝试像这样刷新打印语句:
print("I want to see this", flush=True)
The output of the print statements are not printed out immediately.打印语句的 output 不会立即打印出来。 The flush should force it to be written out before continuing.
刷新应该在继续之前强制它被写出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.