【问题标题】:Start Python script GUI minimized / in Windows Tray | Tkinter启动 Python 脚本 GUI 最小化 / 在 Windows 托盘 |特金特
【发布时间】:2021-11-14 15:58:31
【问题描述】:

我已经构建了一个简单的 GUI 应用程序,并且正在使用 pystray。 实际上,我的脚本像往常一样启动,您首先看到的是 GUI。 如果您单击退出,则 GUI 会最小化,并且会出现托盘图标。

现在,我正在寻找一种方法来在这个“托盘模式”中启动我的脚本 以下是一些信息:

class Hauptfenster:

    # Define a function for quit the window
    def quit_window(icon, item):
        icon.stop()
        fenster.destroy()

    # Define a function to show the window again
    def show_window(icon, item):
        icon.stop()
        fenster.after(0, fenster.deiconify())

    # Hide the window and show on the system taskbar
    @staticmethod
    def hide_window():
        fenster.withdraw()
        image = Image.open(os.path.join(application_path, iconFile))
        menu = (item('Beenden', Frontend.Hauptfenster.quit_window), item('Einstellungen', Frontend.Hauptfenster.show_window))
        icon = pystray.Icon("name", image, "Quicksafe", menu)
        icon.run()

如果您需要更多信息,请询问我,非常感谢! 最好的问候

背景: 我的程序应该放在win10的自动启动中,但我不想每次重启电脑时都最小化窗口

【问题讨论】:

  • @Atlas435一点也不...... pystray 工作正常......但我想从头开始以这种“托盘模式”启动我的程序
  • 因为我不使用这个模块我不能提供代码。但是我不确定为什么不能在代码的__init__ 部分调用您喜欢的函数,这些函数将在您运行此代码后立即执行。我错过了什么?
  • @iWischMob 你可能想使用 pythonw.exe。不确定,但要了解更多信息,请阅读this

标签: python user-interface tkinter pystray


【解决方案1】:

我刚刚将我的方法hide_window 添加到我的主函数中, 当脚本启动时,你会看到一些东西在屏幕上移动了 2 毫秒。但它很快就消失了……所以我可以忍受

【讨论】:

    猜你喜欢
    • 2010-12-08
    • 1970-01-01
    • 2019-09-30
    • 2010-10-19
    • 1970-01-01
    • 1970-01-01
    • 2010-12-16
    • 1970-01-01
    相关资源
    最近更新 更多