Skip to content
Advertisement

how to select a particlular portion of a window’s client area to display in window’s thumbnail in the taskbar in Python/PyQt5/PySide2/Tkinter?

I want to set a particular portion(like only a frame or widget) of my application window to taskbar thumbnail.I found one windows API that is ITaskbarList3::SetThumbnailClip here but this is in C++.I want to do this in python.However PyQt5 contains one class that is Qt Windows Extras which doesnot include this function.I have also found something that show one example here.This link might help you to solve easily. As I am a beginner ,i dont know how to do that properly.

Edit And Fix Me:-

I have tried the second link provided in the question,I have installed comptypes Module through PIP and i have copied taskbarlib.tlb file from github as i have not Windos SDK installed to generate this file as said in the answer here.

Here is my code.

JavaScript

i have got that method to find LP_RECT instance form Ctypes module Doc. hereenter image description here But I have a problem I want to set the frame(blue colored) into taskbar and i got thisenter image description here

Look at the screenshot,the taskbarprogress value that i have set for testing, works fine ,but the thumbnail part is just Unexpected. Can anyone help me to fix this?

Advertisement

Answer

Thanks to Eliya Duskwight to help me slove this. I have corrected my code.

This is For PyQt5 And PySide2 as well as Tkinter

Here is mycode for PyQt5/PySide2

JavaScript

Not only you can use this API for thumbnailclip but also for various functions like ThumbnailToolTip,Taskbar Progress,Taskbar Progressbar,Taskbar Overlay Icon,Adding Buttons etc.You need to read the interface here

>>> For Tkinter

JavaScript

I found root.winfo_id() doesnot give the correct hwnd.I dont know why?So i used hwnd = windll.user32.GetParent(root.winfo_id()) to find the correct one.

Note: This works after the window is visible,So for PyQt5/PySide2,it should be called after calling window.show() & For Tkinter,it should be called after sometime,for that you can use root.after() Or Some event, and You should have that taskbarlib.tlb file pasted in your module folder or in your script folder.You can also generate it using Windows SDK or IDL compiler.Then install comtypes module to work.And remember

The return of S_OK ,means the return of SetThumbnailClip() is 0 always.so anything except 0 is a error.This might crash the application.And As per Microsoft API,the Minimum Required OS is Windows7.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement