2013-12-07 173 views
7

私は、マウスを必要としないフルスクリーンのTkinter Pythonアプリケーションを持っています。それはフルスクリーンを開き、F1を押すとテキストウィジェットを起動します。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() 

起動すると、マウスポインタは表示されません。ただし、テキストウィジェットを開始した後に表示され、テキスト枠と画面の残りの部分との間で形状が変化します。

(パラメータでcursor=''を使用して)マウスカーソルを非表示にする方法についていくつかの記事を見つけましたが、ウィジェット全体でマウスポインタのために機能するものは見つかりませんでした。

Tkinterでマウスポインタを完全に隠す(または無効にする)ことはできますか?

a question on how to set the mouse positionこれは解決策ではありません。self.root.event_generate('<Motion>', warp=True, x=self.root.winfo_screenwidth(), y=self.root.winfo_screenheight())を発行することにより、離れて、このカーソルを移動するために私を助けたが、少なくとも、ポインタが画面の途中から自分の顔にジャンプしません)

答えて

4

私が来ることができる最も近いですFrameを作成してカーソルを 'none'に設定することですが、少なくとも私のマシン(Mac OS X Mavericks)ではカーソルを残してアプリケーションウィンドウに再入力する必要があるという問題があります。たぶん他の誰かが、ときに、アプリケーションのロード消えてカーソルをトリガーする方法を見つけ出すことができますが、ここではこれまでのところ私が持っているコードです:

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

私は推測、

root.config(cursor="none")は動作するはずです。

+0

Windows 10とUbuntu 16の両方で私のために働いた – ChewToy

関連する問題