Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【功能添加】windows下启动服务端和客户端时自动把它们的命令行窗口隐藏到托盘 #40

Open
wjz2001 opened this issue Jan 16, 2024 · 9 comments

Comments

@wjz2001
Copy link

wjz2001 commented Jan 16, 2024

因为我任务栏的东西比较多,如果再增加两个窗口的话就太占地方了,希望可以隐藏到托盘,这样可以节约空间

@wjz2001 wjz2001 changed the title [功能添加]windows下启动服务端和客户端时自动把它们的命令行窗口隐藏到托盘 【功能添加】windows下启动服务端和客户端时自动把它们的命令行窗口隐藏到托盘 Jan 16, 2024
@HaujetZhao
Copy link
Owner

虚拟桌面

@qmzmdqs
Copy link

qmzmdqs commented Jan 16, 2024

可以看看 https://github.com/winsw/winsw ,包装成 Windows 服务。当然软件原本就带了 winsw 的配置就最好了。

@wjz2001
Copy link
Author

wjz2001 commented Jan 21, 2024

虚拟桌面

我在网上教程和chatgpt的帮助写了一个python程序,基本实现了我说的功能,请您将其加入源代码中。

import tkinter as tk
import pystray
from PIL import Image
import subprocess
from queue import Queue

class GUI:
    def __init__(self):
        self.root = tk.Tk()
        self.root.title('演示窗口')
        self.root.geometry("500x200+1100+150")
        self.root.protocol('WM_DELETE_WINDOW', self.hide_window)
        self.create_systray_icon()
        self.interface()
        self.output_queue = Queue()
        self.start_test_script()
        self.hide_window()

    def interface(self):
        self.text_box = tk.Text(self.root, wrap="word")
        self.text_box.pack(expand=True, fill="both")

    def create_systray_icon(self):
        menu = (
            pystray.MenuItem('显示', self.show_window, default=True),
            pystray.Menu.SEPARATOR,
            pystray.MenuItem('退出', self.quit_window))
        image = Image.open("ICO.ico")
        self.icon = pystray.Icon("icon", image, "图标名称", menu)
        threading.Thread(target=self.icon.run, daemon=True).start()

    def hide_window(self):
        self.root.withdraw()

    def show_window(self):
        self.icon.visible = True
        self.root.deiconify()

    def quit_window(self, icon: pystray.Icon):
        icon.stop()
        self.root.quit()
        self.root.destroy()

    def start_test_script(self):
        # 启动test.py并将输出重定向到队列
        process = subprocess.Popen(['python', 'test.py'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
        threading.Thread(target=self.enqueue_output, args=(process.stdout,), daemon=True).start()
        self.root.after(100, self.update_text_box)

    def enqueue_output(self, out):
        for line in out:
            self.output_queue.put(line)

    def update_text_box(self):
        # 从队列中获取输出并显示在文本框中
        while not self.output_queue.empty():
            line = self.output_queue.get()
            self.text_box.insert("end", line)
            self.text_box.see("end")  # 滚动文本框以显示最新输出
        self.root.after(100, self.update_text_box)

if __name__ == '__main__':
    a = GUI()
    a.root.mainloop()

@HaujetZhao
Copy link
Owner

我在网上教程和chatgpt的帮助写了一个python程序,基本实现了我说的功能,请您将其加入源代码中。

两年内不考虑集成 GUI,这东西不是说加就加,而是加上以后新的需求就更不断了。

@H1DDENADM1N
Copy link

@wjz2001 试试我这个 #53

start_server_and_client_in_tray

@wjz2001
Copy link
Author

wjz2001 commented Jan 22, 2024

@wjz2001 试试我这个 #53

start_server_and_client_in_tray start_server_and_client_in_tray

你速度好快😂,我还打算晚上写一个来着。
建议你干脆重新弄个库,把这个gui开源出来,再问问作者能不能把你的仓库的链接放到readme

@H1DDENADM1N
Copy link

H1DDENADM1N commented Jan 22, 2024

你速度好快😂,我还打算晚上写一个来着。 建议你干脆重新弄个库,把这个gui开源出来,再问问作者能不能把你的仓库的链接放到readme

恰好我也需要这个功能,就用ChatGLM4生成了下,AI太强了https://github.com/H1DDENADM1N/CapsWriter-Offline

@GaoYuan522
Copy link

恰好我也需要这个功能,就用ChatGLM4生成了下,AI太强了https://github.com/H1DDENADM1N/CapsWriter-Offline

为什么我的ChatGPT4都写不出来这么华丽的GUI😭

@H1DDENADM1N
Copy link

为什么我的ChatGPT4都写不出来这么华丽的GUI😭

prompt的艺术😆,要先让它角色扮演成为专业的软件工程师

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants