Python + Tkinter Windows 7 任务栏进度

roc*_*ket 4 python windows tkinter progress

我想在任务栏按钮中显示我的应用程序的进度。我用这个答案作为参考。

这是我所做的一个例子:

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()
Run Code Online (Sandbox Code Playgroud)

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

N3R*_*IUM 5

您还可以像这样使用我的库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()
Run Code Online (Sandbox Code Playgroud)

它会自动处理您需要使用 comtypes 执行的所有操作,使其变得更加容易。

文档:这里

免责声明:这个库是我创建的。