[英]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?
我做错了什么?
The tab needs to be activated.需要激活该选项卡。 Add
taskbar.ActivateTab(root.winfo_id())
after taskbar.HrInit()
.在 taskbar.HrInit(
taskbar.ActivateTab(root.winfo_id())
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.在 tkinter 中最好使用
int(root.wm_frame(), 16)
而不是root.winfo_id()
因为否则在 tkinter 选项卡附近会出现一个带有进度条的 python 选项卡。 At the end taskbar.SetProgressState(HWND, TBPF_NOPROGRESS)
should be called to remove the progressbar.最后应调用
taskbar.SetProgressState(HWND, TBPF_NOPROGRESS)
以删除进度条。
The flags need to be defined.需要定义标志。 Eg.
例如。
TBPF_NOPROGRESS = 0
. 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查看 Microsoft 的网页以获取更多选项: 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.我知道这是一个老问题,但也许有人会发现它很有用。
You can also use my library PyTaskbar like this:你也可以像这样使用我的库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()
It automatically handles all the things you need to do with comtypes, making it MUCH easier.它会自动处理您需要对 comtypes 做的所有事情,使其变得更加容易。
如果我是正确的,我认为您需要 .pack 或 .grid 它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.