在Python Gui(PyQt)中运行外部exe

2024-10-01 11:40:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我想运行一个exe(例如计算.exe或者命令提示符)在pythongui中(python2.7 | Windows | PyQt)。 有人知道我怎么做吗? (类似这样:https://www.youtube.com/watch?v=N6GWgxEvibE

提前谢谢大家。在


Tags: httpscomyoutubewindowswwwexepyqtwatch
1条回答
网友
1楼 · 发布于 2024-10-01 11:40:07
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创建进程,运行exe
  • 02使用spy++获取exe的hwnd
  • 03从hwnd创建QWindow
  • 04创建窗口容器

结果:

丢失exe'菜单

相关问题 更多 >