Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to hide or disable the mouse pointer in Tkinter?
Tkinter provides built-in functionality to control window components including the mouse cursor. To hide or disable the mouse pointer in a Tkinter application, you can use the config(cursor="none") method on the root window.
Syntax
The basic syntax to hide the mouse pointer is ?
window.config(cursor="none")
Example
Here's a complete example that creates a window with a hidden mouse pointer ?
# Import tkinter library
from tkinter import *
from tkinter import ttk
# Create an instance of Tkinter frame or window
win = Tk()
# Set the geometry of tkinter frame
win.geometry("750x250")
def callback(event):
win.destroy()
# Create a Label widget
label = ttk.Label(win, text="Press Enter to Close the Window", font=('Century', 17, 'bold'))
label.pack(pady=50)
# Bind Enter key to close window
win.bind('<Return>', callback)
# Hide the Mouse Pointer
win.config(cursor="none")
win.mainloop()
Output
Running the above code will display a window where the mouse pointer becomes invisible when hovering over the window. The window shows the text "Press Enter to Close the Window" and you can close it by pressing the Enter key.
Re-enabling the Mouse Pointer
To restore the default mouse pointer, you can set the cursor back to its default state ?
from tkinter import *
win = Tk()
win.geometry("400x200")
# Initially hide the cursor
win.config(cursor="none")
def show_cursor():
win.config(cursor="") # Empty string restores default cursor
def hide_cursor():
win.config(cursor="none")
# Create buttons to toggle cursor visibility
Button(win, text="Show Cursor", command=show_cursor).pack(pady=20)
Button(win, text="Hide Cursor", command=hide_cursor).pack(pady=10)
win.mainloop()
Different Cursor Options
Besides hiding the cursor completely, Tkinter supports various cursor types ?
| Cursor Type | Description | Usage |
|---|---|---|
"none" |
Hides the cursor | Kiosk applications |
"hand2" |
Pointer hand | Clickable elements |
"watch" |
Loading indicator | Processing operations |
"" |
Default cursor | Normal interaction |
Common Use Cases
Hiding the mouse pointer is useful for ?
- Kiosk applications ? Touch-screen interfaces where mouse interaction is disabled
- Full-screen presentations ? Preventing cursor distractions during slideshows
- Games ? Creating immersive experiences where the cursor should not be visible
- Media players ? Auto-hiding cursor during video playback
Conclusion
Use win.config(cursor="none") to hide the mouse pointer in Tkinter applications. This is particularly useful for kiosk applications, presentations, or any interface where the mouse cursor should not be visible. You can restore the cursor anytime by setting it back to an empty string or another cursor type.
