Skip to content
Related Articles

Related Articles

Changing the Mouse Cursor – Tkinter

Improve Article
Save Article
Like Article
  • Difficulty Level : Basic
  • Last Updated : 24 Jan, 2021

Prerequisite: Python GUI – tkinter

Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python.

In this article, we will learn, how to change the mouse cursor in Tkinter Using Python.

  • A mouse cursor is treated as an indicator, which is used to show the current position of the user position on a computer. It is also called a pointer.
  • Every mouse cursor has its own use. For example, for dragging the image we use fleur mouse cursor, for rotating the text we use exchange mouse cursor etc.

There are about 20 cursors that can be found in Tkinter:

  • arrow
  • circle
  • clock
  • cross
  • dotbox
  • exchange
  • fleur
  • heart
  • man
  • mouse
  • pirate
  • plus
  • shuttle
  • sizing
  • spider
  • spraycan
  • star
  • target
  • tcross
  • trek

Step1: Create Normal Tkinter window and add Button

Python3




# Import Required Library
from tkinter import *
  
# Create Object
root = Tk()
  
# Set geometry
root.geometry("400x400")
  
Button(root,text="Button",font=("Helvetica 15 bold")).pack()
  
# Execute Tkinter
root.mainloop()

Output:

Step2: Add cursor in button

For adding a cursor in Button, use cursor attributes.

Button(root,text="Button",font=("Helvetica 15 bold"),cursor="star").pack()

Use all cursors

  • Make a list, which contains all cursors
  • Iterate through all cursors.

Below is the GUI looks like:-

Below is the implementation:

Python3




# Import Required Library
from tkinter import *
  
# Create Object
root = Tk()
  
# Set geometry
root.geometry("200x530")
  
# List of cursors
cursors =[
        "arrow",
        "circle",
        "clock",
        "cross",
        "dotbox",
        "exchange",
        "fleur",
        "heart",
        "man",
        "mouse",
        "pirate",
        "plus",
        "shuttle",
        "sizing",
        "spider",
        "spraycan",
        "star",
        "target",
        "tcross",
        "trek"
]
  
  
  
# Iterate through all cursors
for cursor in cursors:
    Button(root,text=cursor,cursor=cursor).pack()
  
  
# Execute Tkinter
root.mainloop()

Output:-

For making the cursor globally, use config() method.

Python3




# Import Required Library
from tkinter import *
  
# Create Object
root = Tk()
  
# Set geometry
root.geometry("400x400")
  
# Cursor
root.config(cursor="star")
  
# Execute Tkinter
root.mainloop()

Output:-


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!