Embedding a terminal in PyQt5

前端 未结 1 1741
滥情空心
滥情空心 2020-12-20 00:58

So I\'ve been trying to create my own terminal but that has been proven very glitchy and not professional looking.

Then I stumbled across this code which is for PyQt

相关标签:
1条回答
  • 2020-12-20 01:43

    In PyQt5. winId() returns a <sip.voidptr object at 0x7ff710025aa8> if you convert it to an integer then it will work.

    Here's the working code:

    import sys
    from PyQt5.QtCore import *
    from PyQt5.QtGui import *
    from PyQt5.QtWidgets import *
    
    
    class embterminal(QWidget):
    
        def __init__(self):
            QWidget.__init__(self)
            self.process = QProcess(self)
            self.terminal = QWidget(self)
            layout = QVBoxLayout(self)
            layout.addWidget(self.terminal)
    
            # Works also with urxvt:
            self.process.start(
                    'urxvt',['-embed', str(int(self.winId()))])
            print(self.winId())
            self.setGeometry(1, 1, 800, 600)
    
    
    if __name__ == "__main__":
        app = QApplication(sys.argv)
        main = embterminal()
        main.show()
        sys.exit(app.exec_())
    
    0 讨论(0)
提交回复
热议问题