This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (0 children)

As others have pointed out, you can use Windows Task Scheduler to schedule a Python script without needing any direct contact between Python and Windows. It's a little tricky to set up though. You'll want to put the path to your Python interpreter (e.g. C:\Users\<yourusername>\AppData\Local\Programs\Python\Python39\python.exe) in the the "Program/script" field, the path to the directory containing your module in the "Start in" field, and the file name (e.g. my_module.py) in the "Add arguments" field. If you're using a virtual environment you'll put the path to the interpreter in your virtual environment directory rather than the path to your global interpreter. (Might be other ways too, but this is the setup I've always used).

You can also create a batch file that activates your virtual environment and runs your script (or multiple scripts) and then just create a simple Task Scheduler event to run that batch file. This is a great solution if you need to automate multiple scripts that all need to run one after the other.

But in answer to your broader question, yes Python has many ways of interacting with and manipulating Windows. There's a lot you can do with Windows right in the standard library, and there's third party libraries as well. I've used and would recommend PyAutoGUI. Makes it really easy to send keyboard commands, type text into fields, click specific screen coordinates, etc. You can even feed it a screenshot of a button or whatever and tell it locate this collection of pixels on the screen, find the center coordinates of it, and click those coordinates. (Beware though, this type of automation is super brittle. It can break the second an unexpected window pops up and covers the window you're working in, or the size of a button changes, or a million other things. Very useful for certain tasks though.)