在PyQt中,如何将终端嵌入到窗口中? [英] In PyQt, how can a terminal be embedded in a window?

查看:1460
本文介绍了在PyQt中,如何将终端嵌入到窗口中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小脚本,旨在将xterm嵌入PyQt GUI中.在Linux上,它可以正常工作,并创建如下所示的GUI:

I have a small script that is designed to embed an xterm in a PyQt GUI. On Linux, it works, creating a GUI like this:

但是,在OS X上运行相同的脚本会产生两个这样的窗口:

However, running the same script on OS X yields two windows like this:

有人知道如何解决这个问题并防止OS X破坏GUI吗?

Does anyone know how to address this and prevent OS X from screwing up the GUI?

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class embeddedTerminal(QWidget):

    def __init__(self):
        QWidget.__init__(self)
        self.resize(800, 600)
        self.process = QProcess(self)
        self.terminal = QWidget(self)
        layout = QVBoxLayout(self)
        layout.addWidget(self.terminal)
        self.process.start('xterm', ['-into', str(self.terminal.winId())])

if __name__ == "__main__":
    app = QApplication(sys.argv)
    main = embeddedTerminal()
    main.show()
    sys.exit(app.exec_())

推荐答案

您可以看看 qtconsole Jupyter 的前端,并尝试使用 IPython内核,在另一个应用程序中.

You could take a look at the qtconsole front end for Jupyter and try to use the bash kernel. Depending on your end goal, I know it is possible to embed an IPython kernel, in another application.

这篇关于在PyQt中,如何将终端嵌入到窗口中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆