How to Schedule Python Script using the Windows Scheduler

In this guide, you’ll see the steps to schedule a Python script using the Windows Scheduler.

Here are the steps:

Steps to Schedule Python Script using Windows Scheduler

Step-1: Prepare the Python Script

For example, let’s suppose that the goal is to display ‘Hello Worldeach day at 6am.

Here is the Python script to be used for our example (you may use another Python script based on your needs):

import tkinter as tk

root = tk.Tk()

canvas = tk.Canvas(root, width=300, height=300, bg='deep sky blue')
canvas.pack()

label = tk.Label(root, text='Hello World', font=('Arial', 20))
canvas.create_window(150, 150, window=label)

root.mainloop()

Step-2: Save the Python Script

Once you’re done writing the script, save it as a Python file (where the file extension is .py):

For instance, let’s save the file as hello_world.py under the following path:

C:\Users\Ron\Desktop\Test\hello_world.py

Step-3: Create a Batch File to Run the Python Script

Next, create a batch file to run the Python script.

To start, open Notepad, and then use the following template:

@echo off
"Path where your Python exe is stored\python.exe" "Path where your Python script is stored\script_name.py"
pause

For our example:

  • The path where the Python exe is stored is:
    “C:\Users\Ron\AppData\Local\Programs\Python\Python311\python.exe”
  • The Path where the Python script is stored is (see step-2):
    “C:\Users\Ron\Desktop\Test\hello_world.py”

Here are the paths in the Notepad (you’ll need to adjust those paths to fit your instances):

@echo off
"C:\Users\Ron\AppData\Local\Programs\Python\Python311\python.exe" "C:\Users\Ron\Desktop\Test\hello_world.py"
pause

Finally, save the Notepad with your file name and the “.bat” file extension:

file_name.bat

For example, let’s save the Notepad as:

run_script.bat

After you saved the Notepad, a new batch file (called run_script) would be created at the specified location:

C:\Users\Ron\Desktop\Test\run_script.bat

Step-4: Schedule the Python Script using the Windows Scheduler

In order to schedule the Python script using the Windows Scheduler:

  • Type Task Scheduler in the Windows search bar and then open the app.
  • In the Task Scheduler, select the option to ‘Create Basic Task…’ on the right-side.
  • Type a name for your task (you can also type a description if needed), and then press Next. For instance, let’s name the task as: Run Hello World
  • Choose to start the task ‘Daily‘ since we wish to run the Python script daily at 6am. Also specify the start date and time (6am for our example)
  • Select, Start a program, and then press Next
  • Use the Browse button to find the batch file (run_script.bat) that runs the Python script. In our case:
C:\Users\Ron\Desktop\Test\run_script.bat

Finally, click on Finish, and you should be good to go. From this point onward, you’ll be greeted with ‘Hello World’ everyday at 6am.