-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_tcp.py
44 lines (32 loc) · 1014 Bytes
/
run_tcp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
import sys
import subprocess
import pystray
from PIL import Image
from threading import Thread
import path_identify as pif
def run_example_script():
global tcp_connect_process
tcp_connect_process = subprocess.Popen(["python", "tcp_connect.py"])
def exit_action(icon, item):
tcp_connect_process.terminate()
icon.stop()
sys.exit(0)
def poweroff_action(icon, item):
pif.ss.poweroff();
def poweron_action(icon, item):
pif.ss.poweron();
def create_tray_icon():
icon_path = r"C:\Users\ZF\Pictures\icon\boji1.png" # 您的图标文件路径
image = Image.open(icon_path)
icon = pystray.Icon("name", image, "Running tcp_connect.py")
icon.menu = (
pystray.MenuItem("PowerOff", poweroff_action),
pystray.MenuItem("PowerOn", poweron_action),
pystray.MenuItem("Exit", exit_action),
)
icon.run()
if __name__ == "__main__":
example_thread = Thread(target=run_example_script)
example_thread.start()
create_tray_icon()