I want to use tray icon next to the web socket but if I run the tray icon the web socket will no longer run and if I run the web socket it will no longer run the system tray.
(我想在Web套接字旁边使用任务栏图标,但是如果运行任务栏图标,则Web套接字将不再运行,如果运行Web套接字,它将不再运行系统任务栏。)
Please suggest me a way. (请给我建议一种方法。)
Thanks (谢谢)
Python Code:
(Python代码:)
import asyncio
import websockets
import os
from PIL import Image as logoparser
from pystray import Icon as trayicon, Menu as traymenu, MenuItem as trayitem
host = "localhost"
port = 8765
def return_logo_tray_icon():
return logoparser.open(r'C:UsersjahanDesktopicon.png')
def exit_from_app():
tray_icon.stop()
os._exit(1)
tray_icon = trayicon('POS',return_logo_tray_icon(),menu=traymenu(trayitem('Exit', lambda : exit_from_app()),trayitem('Settings', lambda : show_message("settings clicked"))))
tray_icon.run()
async def handler(websocket, path):
async for message in websocket:
show_message(message)
start_server = websockets.serve(handler, host, port)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
ask by Erfan Jahanshahloo translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…