Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a foreign exe inside a Python GUI (PyQt)

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.

like image 565
SDE Avatar asked Jan 04 '17 22:01

SDE


People also ask

Is PyQt good for GUI?

PyQt is a Python binding for Qt, which is a set of C++ libraries and development tools that include platform-independent abstractions for Graphical User Interfaces (GUI), as well as networking, threads, regular expressions, SQL databases, SVG, OpenGL, XML, and many other powerful features.

How do I run a pyqt5 application?

Next it instantiates an instance of QMainWindow so that PyQt knows what to display as the main app starts. In my experience, I've put setupui() in the init method of the app class. In your case, in the init method of MainCustomerWindow Finally, window. show() tells PyQt to begin rendering the main window.

Is PyQt similar to tkinter?

PyQt have a Qt Designer tool which we can use to build GUIs than get python code of that GUI using Qt Designer. It has no similar tool as Qt Designer for Tkinter.


1 Answers

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

like image 58
chanbiao Avatar answered Oct 05 '22 19:10

chanbiao