问题
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?
回答1:
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.
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.
回答2:
If I'm correct I think you need to .pack or .grid it
来源:https://stackoverflow.com/questions/17607415/python-tkinter-windows-7-taskbar-progress