Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Python/PyQt5/PySide2/Tkinter中选择窗口客户端区域的特定部分以显示在任务栏中的窗口缩略图中? < >我想设置一个特定的窗体,就像我的应用程序窗口的一个框架或窗口,它是一个任务栏缩略图。我找到了一个Windows API,它是IaskBalist3::StTuthNeNaveCress,但是这是C++。我想用Python来做这个。但是PyQT5包含一个类,它是Qt窗口的额外部分,不包括这个函数。我也发现了一些东西。这显示了一个例子。此链接可能会帮助您轻松解决问题。由于我是一个初学者,我不知道如何正确地做到这一点_Python_Python 3.x_Qt_Winapi_Pyqt5 - Fatal编程技术网

如何在Python/PyQt5/PySide2/Tkinter中选择窗口客户端区域的特定部分以显示在任务栏中的窗口缩略图中? < >我想设置一个特定的窗体,就像我的应用程序窗口的一个框架或窗口,它是一个任务栏缩略图。我找到了一个Windows API,它是IaskBalist3::StTuthNeNaveCress,但是这是C++。我想用Python来做这个。但是PyQT5包含一个类,它是Qt窗口的额外部分,不包括这个函数。我也发现了一些东西。这显示了一个例子。此链接可能会帮助您轻松解决问题。由于我是一个初学者,我不知道如何正确地做到这一点

如何在Python/PyQt5/PySide2/Tkinter中选择窗口客户端区域的特定部分以显示在任务栏中的窗口缩略图中? < >我想设置一个特定的窗体,就像我的应用程序窗口的一个框架或窗口,它是一个任务栏缩略图。我找到了一个Windows API,它是IaskBalist3::StTuthNeNaveCress,但是这是C++。我想用Python来做这个。但是PyQT5包含一个类,它是Qt窗口的额外部分,不包括这个函数。我也发现了一些东西。这显示了一个例子。此链接可能会帮助您轻松解决问题。由于我是一个初学者,我不知道如何正确地做到这一点,python,python-3.x,qt,winapi,pyqt5,Python,Python 3.x,Qt,Winapi,Pyqt5,编辑并修复我:- 我已经尝试了问题中提供的第二个链接,我已经通过PIP安装了comptypes模块,并且我已经从中复制了taskbarlib.tlb文件,因为我没有安装Windos SDK来生成此文件,如回答中所述 这是我的密码 from PyQt5.QtWidgets import * import sys ##########----IMPORTING Comtypes module import comtypes.client as cc cc.GetModule('taskbarlib.

编辑并修复我:-

我已经尝试了问题中提供的第二个链接,我已经通过PIP安装了comptypes模块,并且我已经从中复制了taskbarlib.tlb文件,因为我没有安装Windos SDK来生成此文件,如回答中所述

这是我的密码

from PyQt5.QtWidgets import *
import sys
##########----IMPORTING Comtypes module
import comtypes.client as cc
cc.GetModule('taskbarlib.tlb')
import comtypes.gen.TaskbarLib as tb
taskbar=cc.CreateObject('{56FDF344-FD6D-11d0-958A-006097C9A090}',interface=tb.ITaskbarList3)
##################
class MainUiClass(QMainWindow):
     def __init__(self,parent=None):
        super(MainUiClass,self).__init__(parent)
        self.resize(600,400)
        self.frame=QFrame(self)
        self.frame.setGeometry(100,100,400,200)
        self.frame.setStyleSheet('background:blue')
if __name__=='__main__':
      app=QApplication(sys.argv)
      GUI=MainUiClass()
      GUI.show()
      taskbar.HrInit()
      ####--This is just to check its working or not by setting a tasbar progress bar value
      taskbar.SetProgressValue(GUI.winId(),40,100)
      ##########################################
      ##########This is a method to get the LP_RECT instace as per Microsoft API doc.Using Ctypes and got ctypes.wintypes.RECT object  
      from ctypes import POINTER, WINFUNCTYPE, windll, WinError
      from ctypes.wintypes import BOOL, HWND, RECT
      prototype = WINFUNCTYPE(BOOL, HWND, POINTER(RECT))
      paramflags = (1, "hwnd"), (2, "lprect")
      GetWindowRect = prototype(("GetWindowRect", windll.user32), paramflags)
      newrect=GetWindowRect(int(GUI.frame.winId()))
      print(newrect)
      taskbar.SetThumbnailClip(int(GUI.winId()),newrect)
      sys.exit(app.exec_())
我已经找到了从Ctypes模块文档中查找LP_RECT实例的方法。 但我有一个问题,我想把框架设置成蓝色的任务栏,我得到了这个

请看屏幕截图,我为测试设置的taskbarprogress值运行良好,但缩略图部分出乎意料。 有人能帮我解决这个问题吗?

谢谢Eliya Dashwight帮我解决这个问题。 我已经更正了我的代码

这是针对PyQt5和PySide2以及Tkinter的

这是PyQt5/PySide2的mycode

from PyQt5.QtWidgets import *          ###For PyQt5
from PySide2.QtWidgets import *        ###For PySide2
import sys
###Most Important Part###
import comtypes.client as cc
cc.GetModule('taskbarlib.tlb')
import comtypes.gen.TaskbarLib as tb
taskbar=cc.CreateObject('{56FDF344-FD6D-11d0-958A-006097C9A090}',interface=tb.ITaskbarList3)
class MainUiClass(QMainWindow):
   def __init__(self,parent=None):
        super(MainUiClass,self).__init__(parent)
        self.resize(600,400)
        self.setStyleSheet('background:red')
        self.frame=QFrame(self)
        self.frame.setGeometry(100,100,400,200)
        self.frame.setStyleSheet('background:blue')
if __name__=='__main__':
      app=QApplication(sys.argv)
      GUI=MainUiClass()
      GUI.show()
      taskbar.HrInit()
      ##You need to find "hwnd" of your Window and "LP_RECT" instance of Geometry you want, as per Microsoft API Doc. using Ctypes
      from ctypes.wintypes import  RECT,PRECT 
      newrect=PRECT(RECT(0,0,600,400))
      taskbar.SetThumbnailClip(int(GUI.winId()),PRECT(RECT(0,0,600,400)))
您不仅可以将此API用于thumbnailclip,还可以用于各种功能,如ThumbnailToolTip、任务栏进度、任务栏进度栏、任务栏覆盖图标、添加按钮等。您需要阅读该界面

>>>特金特酒店

我发现root.winfo_id没有给出正确的hwnd。我不知道为什么?所以我使用hwnd=windell.user32.GetParentroot.winfo_id来找到正确的

注: 这在窗口可见后工作,因此对于PyQt5/PySide2,应该在调用window.show之后调用它&对于Tkinter,应该在某个时间之后调用它,因为您可以使用root.after或某个事件,您应该将taskbarlib.tlb文件粘贴到模块文件夹或脚本文件夹中。您也可以使用Windows SDK或IDL编译器生成该文件。然后安装comtypes模块以使其工作。请记住


< S> OK的返回,意味着StTrimNeNeC++的返回是0。所以,除了0以外,任何一个都是一个错误。这可能会破坏应用程序。根据微软API,最小的操作系统是Windows 7。它相当于C语言,并不重要,因为ITaskbarList是一个COM接口,语言不可知。尝试找到一个为您处理COM的Python模块。也许是的,你必须自己看看。检查这个链接。你可能很容易解决这个问题。我不知道怎么做,因为对于像我这样的初学者来说,这些模块非常冗长,很难理解@llnspectable QWinThumbnailToolBar类看起来很简单,您只需使用@Rajkumar 1设置pixmap即可。你的问题不是问题,而是问题。2.如果你找到了答案,不要编辑问题,提供你自己的答案,不要把问题解决,请关闭等等。你已经在这里有一段时间了,你应该已经知道这个地方不仅仅是为你:问题和答案是为每个人。3.我们为什么要关闭它?如果其他人也有类似的问题呢?4.请不要添加来自某个地方的屏幕截图来解释解决方案,它绝对没有意义,它非常烦人且难以阅读,并且对您的帖子没有任何帮助。我已经回滚了您的编辑。答案永远不属于这个问题。相反,你应该在下面为你的问题贴出一个正确的答案。有关详细信息,请参阅:
from tkinter import *
from ctypes import windll
from ctypes.wintypes import  RECT,PRECT
###Most Important Part###
import comtypes.client as cc
cc.GetModule('taskbarlib.tlb')
import comtypes.gen.TaskbarLib as tb
taskbar=cc.CreateObject('{56FDF344-FD6D-11d0-958A-006097C9A090}',interface=tb.ITaskbarList3)
root=Tk()
root.geometry("400x300")
root.config(bg="red")
frame=Frame(root,bg='blue',width=200,height=100)
frame.place(x=100,y=100)

def setThumbnail():
   hwnd = windll.user32.GetParent(root.winfo_id())
   print(hwnd)
   taskbar.HrInit()
   taskbar.SetThumbnailClip(hwnd,PRECT(RECT(0,0,60,60)))#Geometry You Want To Set
root.after(1000,setThumbnail)   
root.mainloop()