4

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?

3 Answers 3

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is great, but, I don't like that you hide the IDL -> TLB file creation. Not that you have anything nefarious planned, but if the IDL file were to change, the TLB file would change - plus if we want to tweak it by adding/removing functions, we can't easily do so.
5

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.

1 Comment

It's also quite important to initialize HWND after you start rendering the window — because the wm_frame() value changes. So you should either init your taskbar on the run, or call root.update() once before you call wm_frame().
-3

If I'm correct I think you need to .pack or .grid it

1 Comment

Here, taskbar is a COM object, not a tkinter widget. I don't want do place it anywhere on a window (and I couldn't even if I needed to - it does not have these methods).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.