In this video I’ll show you how to change the mouse cursor in your app with Tkinter and Python.

There are about 20 cursors you can count on:
arrow
circle
clock
cross
dotbox
exchange
fleur
heart
man
mouse
pirate
plus
shuttle
sizing
spider
spraycan
star
target
tcross
trek

To use them, just set the cursor attribute in whatever widget you want to use them in.

Button(root, text=”whatever”, cursor=”target”)

And it’s just that easy!

Python Code: cursor.py
(Github Code)

from tkinter import *

root = Tk()
root.title("Cursors")
root.geometry("500x550")
root.iconbitmap('c:/guis/exe/codemy.ico')
root.config(cursor="fleur")

list = [
    "arrow",
    "circle",
    "clock",
    "cross",
    "dotbox",
    "exchange",
    "fleur",
    "heart",
    "man",
    "mouse",
    "pirate",
    "plus",
    "shuttle",
    "sizing",
    "spider",
    "spraycan",
    "star",
    "target",
    "tcross",
    "trek",
]

count = 0
row1=0
row2=0
row3=0
row4=0

for cursor in list:
	if count < 5:
		Button(root, text=cursor, cursor=cursor, width=10, height=5, fg="darkblue").grid(row=row1, column=0, pady=10, padx=10)
		row1 += 1
		count += 1

	elif count >= 5 and count < 10:
		Button(root, text=cursor, cursor=cursor, width=10, height=5, fg="darkblue").grid(row=row2, column=1, pady=10, padx=10)
		row2 += 1
		count += 1

	elif count >= 10 and count < 15:
		Button(root, text=cursor, cursor=cursor, width=10, height=5, fg="darkblue").grid(row=row3, column=2, pady=10, padx=10)
		row3 += 1
		count += 1

	else:
		Button(root, text=cursor, cursor=cursor, width=10, height=5, fg="darkblue").grid(row=row4, column=4, pady=5, padx=5)
		row4 += 1
		count += 1		

root.mainloop()

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of the first dot com boom. After that he developed the award-winning Submission-Spider search engine submission software that's been used by over 3 million individuals, businesses, and governments in over 42 countries. He's written several Amazon #1 best selling books on coding, and runs a popular Youtube coding channel.

View all posts

Add comment

Your email address will not be published. Required fields are marked *

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of...