8

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 : https://www.youtube.com/watch?v=N6GWgxEvibE)

Thanks all in advance.

SDE
  • 129
  • 1
  • 7
  • Does this have to work in PyQt4, or could you use PyQt5? I think you may need the latter to get this to work on Windows. (I assume you're asking about embedding external windows in your own application). – ekhumoro Jan 05 '17 at 00:30
  • How can i make it with PyQt5? I want to include the cmd.exe there. In linux i had done this with xterm and fit it into a qwidget successfully. But in windows this doesnt work :(. Thx in advance. – SDE Jan 05 '17 at 11:55
  • What do you mean by run an exe inside a python gui? – NoDataDumpNoContribution Jan 05 '17 at 13:32
  • @SDE What does embedding another app's window in your app provide, over just starting the other app as a separate process? – Oliver Jan 06 '17 at 05:44
  • @Schollii Yes. It should work like the youtube link, which i have post above. I have now change to pyqt5. – SDE Jan 11 '17 at 10:57
  • @SDE would you have a full solution example to this question for me? I am aiming to achieve the same thing however I can't find the complete solution – Andrie Jul 10 '20 at 18:53

1 Answers1

9
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

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
chanbiao
  • 91
  • 1
  • 2