Run a foreign exe inside a Python GUI (PyQt)

前端 未结 1 1559
我在风中等你
我在风中等你 2020-11-28 15:00

I want to run an exe (for example calc.exe or cmd.exe) inside a python gui (python 2.7 | Windows | PyQt). Have anybody an idea how can i do this? (something like that : htt

相关标签:
1条回答
  • 2020-11-28 15:30
    import subprocess
    import time
    import win32gui
    
    ...
    
    def initUI(self):
        # create a process
        exePath = "C:\\Windows\\system32\\calc.exe"
        subprocess.Popen(exePath)
        hwnd = win32gui.FindWindowEx(0, 0, "CalcFrame", "计算器")
        time.sleep(0.05)
        window = QWindow.fromWinId(hwnd)
        self.createWindowContainer(window, self)
        self.setGeometry(500, 500, 450, 400)
        self.setWindowTitle('File dialog')
        self.show()
    
    ...
    
    • 01 create a process, run your exe
    • 02 use spy++ to get hwnd of the exe
    • 03 create QWindow from hwnd
    • 04 create window container

    Result:

    lose exe'menu

    0 讨论(0)
提交回复
热议问题