Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

python - 如何在python中的系统托盘旁边使用websocket(How to use websocket beside system tray in python)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...