- 1 year ago
How to keep track of time on all windows with Python?
To keep track of time on all windows using Python, you can use the pygetwindow
module. This module allows you to interact with windows on your desktop, including getting the title of the window and its position on the screen.
Here is an example Python script that uses pygetwindow
to keep track of time for all open windows:
perlimport pygetwindow
import time
while True:
for window in pygetwindow.getAllTitles():
print(window + ": " + time.strftime("%H:%M:%S"))
time.sleep(1)
This script first imports the pygetwindow
and time
modules. It then enters an infinite loop that iterates over all windows on the desktop using the getAllTitles
method of pygetwindow
. For each window, it prints the window title and the current time using time.strftime
. The script then sleeps for one second before repeating the loop.
Note that this script will only work while it is running, and will not keep track of time for windows that are opened or closed while the script is not running.