.py プログラムの起動時に呼び出されるクラスがあり、Windows タスク バーにアイコン トレイが作成されます。quit
その中には、私のクラスの関数にマップされたオプションがありkill_icon_tray
、アイコンを終了してからプログラムを終了する必要があります。
これはクラスです (一部のメソッドは不要であるため省略されています)。
from infi.systray import SysTrayIcon
class Tray_icon_controller:
def __init__(self):
self.menu_options = (("Open Chat Monitor", None, self.open_chat),)
self.systray = SysTrayIcon("chat.ico", "Engineer Reminder", self.menu_options, on_quit=self.kill_icon_tray);
def init_icon_tray(self):
self.systray.start();
def kill_icon_tray(self, systray):
self.systray.shutdown()
quit
しかし、アイコントレイをクリックするたびに、次の例外が返されます。
$ py engineer_reminder.py
Traceback (most recent call last):
File "_ctypes/callbacks.c", line 237, in 'calling callback function'
File "C:\Users\i866336\AppData\Local\Programs\Python\Python38-32\lib\site-packages\infi\systray\traybar.py", line 79, in WndProc
self._message_dict[msg](hwnd, msg, wparam.value, lparam.value)
File "C:\Users\i866336\AppData\Local\Programs\Python\Python38-32\lib\site-packages\infi\systray\traybar.py", line 195, in _destroy
self._on_quit(self)
File "C:\Users\i866336\Documents\GitHub\chat_reminder\cl_tray_icon_controller.py", line 17, in kill_icon_tray
self.systray.shutdown()
File "C:\Users\i866336\AppData\Local\Programs\Python\Python38-32\lib\site-packages\infi\systray\traybar.py", line 123, in shutdown
self._message_loop_thread.join()
File "C:\Users\i866336\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 1008, in join
raise RuntimeError("cannot join current thread")
RuntimeError: cannot join current thread
kill_icon_tray
代わりにメソッドをこれに変更しようとしましたが、同じ例外がスローされました:
def kill_icon_tray(self, systray):
self.systray.shutdown()
infi.systray
ドキュメントに従って、私はそれを正しくやっています:
プログラムの終了時にアイコンを破棄するには、呼び出します
systray.shutdown()
ここで何が欠けているのかわかりません...誰か助けてもらえますか?ありがとう!