9

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.

6
  • 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). Commented Jan 5, 2017 at 0: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. Commented Jan 5, 2017 at 11:55
  • What do you mean by run an exe inside a python gui? Commented Jan 5, 2017 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? Commented Jan 6, 2017 at 5:44
  • @Schollii Yes. It should work like the youtube link, which i have post above. I have now change to pyqt5. Commented Jan 11, 2017 at 10:57

1 Answer 1

11
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

Sign up to request clarification or add additional context in comments.

2 Comments

Can this be extended to work on Linux, any ideas or suggestions?
Could you provide the full code that runs this example? Thank sir.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.