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?
You can also use my library PyTaskbar like this:
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.
Docs: Here
Disclaimer: this library was made by me.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With