Python + Tkinter Windows 7 任务栏进度 [英] Python + Tkinter Windows 7 taskbar progress
问题描述
我想在任务栏按钮中显示我的应用程序的进度.我使用这个答案作为参考.
I want to show the progress of my app in a taskbar button. I used this answer as a reference.
这是我所做的一个例子:
Here's an example of what I do:
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()
但我在任务栏按钮上看不到任何进展.我做错了什么?
But I see no progress on a taskbar button. What do I do wrong?
推荐答案
需要激活选项卡.在taskbar.HrInit()
之后添加taskbar.ActivateTab(root.winfo_id())
.在 tkinter 中最好使用 int(root.wm_frame(), 16)
而不是 root.winfo_id()
因为否则在 tkinter 选项卡附近会出现一个带有进度条的 python 选项卡.最后应该调用 taskbar.SetProgressState(HWND, TBPF_NOPROGRESS)
来移除进度条.
The tab needs to be activated. Add taskbar.ActivateTab(root.winfo_id())
after taskbar.HrInit()
.
In tkinter is better to use int(root.wm_frame(), 16)
instead root.winfo_id()
because otherwise near tkinter tab will appear a python tab with a progressbar.
At the end taskbar.SetProgressState(HWND, TBPF_NOPROGRESS)
should be called to remove the progressbar.
需要定义标志.例如.TBPF_NOPROGRESS = 0
.查看 Microsoft 网页以获取更多选项:https://msdn.microsoft.com/en-us/library/windows/desktop/dd391697%28v=vs.85%29.aspx
The flags need to be defined. Eg. TBPF_NOPROGRESS = 0
.
Check Microsoft's webpage for more options: https://msdn.microsoft.com/en-us/library/windows/desktop/dd391697%28v=vs.85%29.aspx
我知道这是一个老问题,但也许有人会觉得它有用.
I know this is an old question but maybe someone will find it useful.
这篇关于Python + Tkinter Windows 7 任务栏进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!