Python Tkinter section

How to Customize A Mouse Cursor with An Image - Python Tkinter

Post by Amina Delali, February 20th, 2025

Description

You want customized cursors for your python application, this is how you do it.

  • Prepare the image:
    • create or download the image you want to use
    • convert it to a cur image => you can see in this website
  • Integrate it in your code:
    • define cursor values which are special paths to the previously created cursor files
    • set the cursor property of each widget to the one of the new created cursor values

Image Preparation

After Selecting the images you want to work with, you will have to convert them to .cur files.

There are websites that offer conversion for free. I converted the images used in this post with the Convertio website. I used these two images, downloaded from Icons8.com

images used as custom cursors

One of the two images, will be used for the mouse cursor when hovering above a button widget. The other one, will be used when hovering over the application's main window (outside the button's area).

Code Integration

As mentioned earlier, you will simply have to set the cursor property for the widget (or the main window) to a custom cursor value. To create that custom value, you simply use the path of the images as follow:

how to define the path of a custom cursor image in python tkinter app

Now, all you have to do, is to do is to assign the new values (cursor_1 and cursor_2) to the property cursor of the button and of the application's main window, as described in the image below.

how to set the cursor property of a python tkinter widget

Youtube Video

In the following YouTube video, the same code is explained. The only thing different, is that I am using other images.

You can find the corresponding code below 🙂



Code

from tkinter import TkButton


cursor_1 "@cursor-1.cur"
cursor_2 "@cursor-2.cur"

main_window Tk()
main_window.geometry("600x200+500+100")
main_window.title("Custom Cursors")
main_window.iconbitmap(bitmap="submark.ico")

main_window.configure(bg="#6F732F",cursor=cursor_1)


button Button(main_window,text="Click Me!",
                cursor=cursor_2,
                width=30font=("Arial",14),
                bg="#D282A6",fg="#F3E9DC",)

button.pack(pady=50padx=50)


main_window.mainloop()

The Output



Something to say?

If you want to add something about this post, please feel free to do it by commenting below 🙂.