Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14011

Is there a Python equivalent to JavaScript's requestAnimationFrame()?

$
0
0

In JavaScript, there is a function window.requestAnimationFrame(). This function allows you to run a callback function every time the screen is about to updated.

I want to use a similar function in Python in order to see what was just drawn on the screen. currently, I am simply just running a while loop and using PIL.ImageGrab() to read the screen:

while True:  screen = PIL.ImageGrab.grab()  if screen.getpixel((0, 0)) == (1, 2, 3):    print("Pixel (0, 0) is rgb(1, 2, 3)")

I would like to replace the while loop with a function like JavaScript's window.requestAnimationFrame(). Here is an example of using requestAnimationFrame() in JS:

function beforeFrameDrawn() {  console.log("A frame is about to be drawn!");  requestAnimationFrame(beforeFrameDrawn);}requestAnimationFrame(beforeFrameDrawn);

The above code is somewhat recursive. I want to use a similar function in Python, if possible. I am open to installing external libraries. I am using Python 3.11.


Viewing all articles
Browse latest Browse all 14011

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>