In PyQt, how can a terminal be embedded in a windo

2019-07-04 06:08发布

问题:

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:

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

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_())

回答1:

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.