How can I draw a circle over a chrome window(or another window) using python

Question:

I want to draw a circle over chrome, where I have the center(coordinates) and radius..

I tried turtle but it opens up a new window, also, a transparent layer does not work for me :’)

Asked By: Dark Soul

||

Answers:

To draw a circle over a Chrome window (or any other window) using Python, you can use the pyautogui library. pyautogui is a Python library for automating mouse and keyboard actions.

Here’s an example of how you can use pyautogui to draw a circle over a Chrome window:

import pyautogui

# Move the mouse to the center of the window
window_center = pyautogui.locateCenterOnScreen('chrome_window.png')
pyautogui.moveTo(window_center)

# Draw the circle
radius = 50
pyautogui.dragRel(radius, 0, duration=0.2) # draw right
pyautogui.dragRel(0, radius, duration=0.2) # draw down
pyautogui.dragRel(-radius, 0, duration=0.2) # draw left
pyautogui.dragRel(0, -radius, duration=0.2) # draw up

In this example, we first use the locateCenterOnScreen method to find the center of the Chrome window. This method takes a screenshot of the screen and searches for an image of the Chrome window. Once the center of the window is found, we move the mouse to that position using the moveTo method.

Next, we draw the circle using the dragRel method. This method moves the mouse relative to its current position, drawing a line as it moves. We first draw a line to the right, then down, left, and up to complete the circle.

Note that this will draw the circle over the entire window, not just over the Chrome browser. If you only want to draw the circle over the Chrome browser, you may need to use a browser extension or other specialized tools.

Answered By: Samson Olamide
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.