Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide or disable the mouse pointer in Tkinter?

I have a fullscreen Tkinter Python application which does not need the mouse -- a simplified version is below. It opens fullscreen and activates a text widget upon pressing F1.

import Tkinter as tk

class App():
    def __init__(self):
        self.root = tk.Tk()
        self.root.attributes('-fullscreen', True)
        self.root.configure(background='red')
        self.root.bind('<F1>', self.opennote)
        self.root.bind('<F2>', self.closenote)
        self.root.bind('<F3>', self.quit)
        l = tk.Label(text="some text here")
        l.pack()
        self.root.mainloop()

    def opennote(self, event):
        self.n = tk.Text(self.root, background='blue')
        self.n.pack()

    def closenote(self, event):
        self.n.destroy()

    def quit(self, event):
        self.root.destroy()

App()

When launched, the mouse pointer is not visible. It becomes visible, though, after initiating the Text widget, and then stays (changing shape between the text frame and the rest of the screen).

I found several articles about how to hide a mouse cursor (by using cursor='' in parameters) but I did not find anything which would work for the mouse pointer across the widgets.

Is it possible to completely hide (or disable) the mouse pointer in Tkinter?

(a question on how to set the mouse position helped me to move this cursor away by issuing a self.root.event_generate('<Motion>', warp=True, x=self.root.winfo_screenwidth(), y=self.root.winfo_screenheight()). This is not a solution but at least the pointer does not jump in one's face from the middle of the screen)

like image 587
WoJ Avatar asked Dec 07 '13 21:12

WoJ


People also ask

How do I disable my mouse pointer?

The “Pointer Options” tab displays various mouse settings. Here, in the “Visibility” section, enable the “Hide Pointer While Typing” option. Then click “Apply” and “OK.” And you're all set.

How do you hide something in Tkinter?

We could hide the Tkinter widgets by calling pack_forget() method to make the widgets invisible. We need to call the pack() method again to pack the widget to make it visible, or to recover it. We can also delete Tkinter widgets permanently by calling the destroy() method in this section.

How do you disable the Close button in Tkinter?

Disable Exit (or [ X ]) in Tkinter Window To disable the Exit or [X] control icon, we have to define the protocol() method. We can limit the control icon definition by specifying an empty function for disabling the state of the control icon.

How do I disable keyboard and mouse in Python?

import pyHook from threading import Timer import win32gui import logging class blockInput(): def OnKeyboardEvent(self,event): return False def OnMouseEvent(self,event): return False def unblock(self): logging.info(" -- Unblock! ") if self.


1 Answers

I guess,

root.config(cursor="none") should work.

like image 184
dhruvvyas90 Avatar answered Oct 01 '22 18:10

dhruvvyas90