Python + Tkinter Windows 7 任务栏进度

标签 python windows tkinter progress

我想在任务栏按钮中显示我的应用程序的进度。 我用了this answer作为引用。

这是我所做的一个例子:

import tkinter

import comtypes.client as cc
cc.GetModule("TaskbarLib.tlb")

import comtypes.gen.TaskbarLib as tbl
taskbar = cc.CreateObject(
    "{56FDF344-FD6D-11d0-958A-006097C9A090}",
    interface=tbl.ITaskbarList3)

class gui(object):
    def __init__(self, root):
        self.root = root

if __name__ == "__main__":
    root = tkinter.Tk()
    app = gui(root)

    taskbar.HrInit()
    taskbar.SetProgressValue(root.winfo_id(),40,100)

    root.mainloop()

但是我在任务栏按钮上看不到任何进展。我做错了什么?

最佳答案

你也可以使用我的图书馆PyTaskbar像这样:

import tkinter
import PyTaskbar # the module

class gui(object):
    def __init__(self, root):
        self.root = root

if __name__ == "__main__":
    root = tkinter.Tk()
    app = gui(root)

    taskbar_progress = PyTaskbar.Progress(root.winfo_id()) # Instantiate a new progress object
    taskbar_progress.init() # Initialize the progress bar
    taskbar_progress.setState("normal") # Set the progress bar state to normal (Available: loading, normal, warning, error)
    taskbar_progress.setProgress(50) # Set the progress bar value to 50%

    root.mainloop()

它会自动处理您需要使用 comtypes 做的所有事情,使其变得更加容易。

文档:Here

关于Python + Tkinter Windows 7 任务栏进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17607415/

相关文章:

python - 访问存储在 pandas dataframe 中的数组

windows - windows 的 "notify-send"等效项是什么?

linux - 需要帮助将 .sh 文件转换为 .bat

windows - 通过命令行/通过 Jenkins "Execute Batch Command"创建安装程序

python - 如何更新 python tkinter 窗口

python - 使用 tkinter 变量查询 MySQL 数据库

python - Gunicorn 工作线程在请求​​后不会压缩内存

python - 在 Django 中访问同一数据库中的其他表

python - 快速检查远程 URL 上的图像是否存在于 python 中

python-3.x - Tkinter 专注于弹出窗口