2013-12-07 18 views
7

Ho un'applicazione Tkinter Python a schermo intero che non ha bisogno del mouse - una versione semplificata è qui sotto. Si apre a schermo intero e attiva un widget di testo premendo F1.Come nascondere o disabilitare il puntatore del mouse in Tkinter?

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() 

All'avvio, il puntatore del mouse non è visibile. Diventa visibile, tuttavia, dopo aver avviato il widget Testo, e quindi rimane (cambiando forma tra la cornice di testo e il resto dello schermo).

Ho trovato diversi articoli su come nascondere un cursore del mouse (utilizzando cursor='' nei parametri) ma non ho trovato nulla che avrebbe funzionato per il puntatore del mouse attraverso i widget.

È possibile nascondere (o disabilitare) completamente il puntatore del mouse in Tkinter?

(a question on how to set the mouse position mi ha aiutato a spostare il cursore lontano emettendo un self.root.event_generate('<Motion>', warp=True, x=self.root.winfo_screenwidth(), y=self.root.winfo_screenheight()). Questa non è una soluzione, ma almeno il puntatore non saltare dentro la faccia dal centro dello schermo)

risposta

4

Il più vicino che posso venire è quello di creare un Frame e impostare il cursore su "nessuno", ma ha ancora il problema di richiedere al cursore di uscire e rientrare nella finestra dell'app, almeno sulla mia macchina (Mac OS X Mavericks). Forse qualcun altro riesce a capire come attivare il cursore a scomparire quando l'applicazione carica, ma qui è il codice che ho finora:

import Tkinter as tk 


class App(): 
    def __init__(self): 
     self.root = tk.Tk() 
     self.root.attributes('-fullscreen', True) 
     self.main_frame = tk.Frame(self.root) 
     self.main_frame.config(background='red', cursor='none') 
     self.main_frame.pack(fill=tk.BOTH, expand=tk.TRUE) 
     self.root.bind('<F1>', self.opennote) 
     self.root.bind('<F2>', self.closenote) 
     self.root.bind('<F3>', self.quit) 
     l = tk.Label(self.main_frame, text="some text here") 
     l.pack() 
     self.root.mainloop() 

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

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

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

App() 
16

immagino,

root.config(cursor="none") dovrebbe funzionare.

+0

Ha funzionato per me sia con Windows 10 che con Ubuntu 16 – ChewToy

Problemi correlati