# -*- coding: utf-8 -*- import sys import win32gui from PyQt5.QtGui import QWindow from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QHBoxLayout, QPushButton from PyQt5.QtCore import Qt class MyWidget(QWidget): def __init__(self, parent=None): super(MyWidget, self).__init__(parent) layout = QVBoxLayout(self) btnLayout = QHBoxLayout() embedBtn = QPushButton("embed") popupBtn = QPushButton("popup") btnLayout.addWidget(embedBtn) btnLayout.addWidget(popupBtn) layout.addLayout(btnLayout) embedBtn.clicked.connect(self.embed) popupBtn.clicked.connect(self.popup) self.window = None self.windowWidget = None self.hwnd = None self.resize(400, 400) def embed(self): self.hwnd = win32gui.FindWindow(None, "block application") if self.hwnd: self.window = QWindow.fromWinId(self.hwnd) self.windowWidget = QWidget.createWindowContainer(self.window) self.layout().addWidget(self.windowWidget) win32gui.SetParent(self.hwnd, int(self.winId())) def popup(self): self.window.setParent(None) self.window.setFlags(Qt.Window) self.windowWidget.setParent(None) self.windowWidget.destroy() win32gui.SetParent(self.hwnd, 0) win32gui.UpdateWindow(self.hwnd) if __name__ == '__main__': app = QApplication(sys.argv) widget = MyWidget() widget.show() app.exec_()