How to hide or disable the mouse pointer in Tkinter?

PythonTkinterServer Side ProgrammingProgramming

There are several ways to disable and enable a particular widget in a Tkinter application. However, if we want to control the Tkinter window components such as mouse cursor, control icons, toolbars, then Tkinter provides several built-in functions which can be used to configure the Tkinter window objects.

To hide or disable the mouse pointer for a particular Tkinter application, then we can configure the mouse property using config(mouse= "none") method. It can be invoked for the master or root window.

Example

#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 and a Button widget
label=ttk.Label(win, text="Press Enter to Close the Window", font=('Century 17 bold'))
label.pack(ipadx=10)
win.bind('<Return>',callback)
#Disable the Mouse Pointer
win.config(cursor="none")
win.mainloop()

Output

Running the above code will hide or disable the Mouse Pointer for the window.

Now, while residing in the window, press Enter that will force the window to close.

raja
Published on 22-Apr-2021 07:10:35
Advertisements