![](/img/trans.png)
[英]Python-Tkinter:how to highlight item on taskbar on windows xp when window is minimized to the taskbar
[英]Python + Tkinter Windows 7 taskbar progress
我想在任务栏按钮中显示我的应用程序的进度。 我用这个答案作为参考。
这是我所做的一个例子:
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()
但我看到任务栏按钮没有任何进展。 我做错了什么?
需要激活该选项卡。 在 taskbar.HrInit( taskbar.ActivateTab(root.winfo_id())
taskbar.HrInit()
。 在 tkinter 中最好使用int(root.wm_frame(), 16)
而不是root.winfo_id()
因为否则在 tkinter 选项卡附近会出现一个带有进度条的 python 选项卡。 最后应调用taskbar.SetProgressState(HWND, TBPF_NOPROGRESS)
以删除进度条。
需要定义标志。 例如。 TBPF_NOPROGRESS = 0
。 查看 Microsoft 的网页以获取更多选项: https ://msdn.microsoft.com/en-us/library/windows/desktop/dd391697%28v=vs.85%29.aspx
我知道这是一个老问题,但也许有人会发现它很有用。
你也可以像这样使用我的库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()
它会自动处理您需要对 comtypes 做的所有事情,使其变得更加容易。
文档: 这里
如果我是正确的,我认为您需要 .pack 或 .grid 它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.