2017-07-02 14 views
-1

SysTrayIcon.pyは、Windowsで簡単にSystrayアイコンを作成することができました。このコードを言うことができますコードを実行しているSystrayコードの実行

import _tray #This is a simple import of SysTrayIcon.py 

#Create SysTray 
def EXIT(self): None 
def DEBUG(self): print("TEST") 
def SHOW(self): print("Showing Main Window") 
HOVER = "Foo v"+version 
ICON = root+"apr.ico" 
MENUE =(('1', None, DEBUG), 
     ('2', None, SHOW), 
     ('Sub', None, (
      ('Sub 1', None, DEBUG), 
      ('Sub 2', None, DEBUG),))) 

_tray.SysTrayIcon(ICON, HOVER, MENUE, on_quit=EXIT, default_menu_index=1) 

私は今追加した場合::へ

print("This get's executed after the Trayicon is quit.") 

問題は、一例として、これは私が私の現在のトレイアイコンを作成する方法で、コードのさらなる実行をブロックしている、ありますTrayiconを終了するまで、他のコードは実行されません。どのようにして動作を回避/修正できますか?

答えて

1

スレッドを使用して、アプリケーションロジックからWIN32 APIコンテキストホールドを分離できます。たとえば、場合は、との直接の呼び出しを置き換える:

import threading 

def run_systray(icon, hover, menu, **options): 
    _tray.SysTrayIcon(icon, hover, menu, **options) 

thread = threading.Thread(target=run_systray, 
          args=(ICON, HOVER, MENUE), 
          kwargs={"on_quit": EXIT, "default_menu_index": 1}) 
thread.start() 

print("This gets executed immediately...") 

# you can do whatever you want here 

# in the end, lets cleanly handle the thread closing: 
thread.join() 

print("This gets executed only after systray exit...") 

SysTrayIconクラスは喜んであなたが戻ってメインの1にスレッドに参加することを決定するまでのコードの残りの部分をブロックすることなく、WIN32 APIでチャットします。

+0

まさに私が欲しかったこと、ありがとう! – Lyux

関連する問題