• <bdo id='HTbEx'></bdo><ul id='HTbEx'></ul>

    <small id='HTbEx'></small><noframes id='HTbEx'>

    1. <i id='HTbEx'><tr id='HTbEx'><dt id='HTbEx'><q id='HTbEx'><span id='HTbEx'><b id='HTbEx'><form id='HTbEx'><ins id='HTbEx'></ins><ul id='HTbEx'></ul><sub id='HTbEx'></sub></form><legend id='HTbEx'></legend><bdo id='HTbEx'><pre id='HTbEx'><center id='HTbEx'></center></pre></bdo></b><th id='HTbEx'></th></span></q></dt></tr></i><div id='HTbEx'><tfoot id='HTbEx'></tfoot><dl id='HTbEx'><fieldset id='HTbEx'></fieldset></dl></div>

      <legend id='HTbEx'><style id='HTbEx'><dir id='HTbEx'><q id='HTbEx'></q></dir></style></legend>

    2. <tfoot id='HTbEx'></tfoot>

      1. 如何在没有 QProcess 的情况下将终端嵌入 PyQt5 应用

        时间:2023-08-05
        <legend id='5Az9e'><style id='5Az9e'><dir id='5Az9e'><q id='5Az9e'></q></dir></style></legend>
      2. <tfoot id='5Az9e'></tfoot>

            <tbody id='5Az9e'></tbody>

            <small id='5Az9e'></small><noframes id='5Az9e'>

                <bdo id='5Az9e'></bdo><ul id='5Az9e'></ul>
                • <i id='5Az9e'><tr id='5Az9e'><dt id='5Az9e'><q id='5Az9e'><span id='5Az9e'><b id='5Az9e'><form id='5Az9e'><ins id='5Az9e'></ins><ul id='5Az9e'></ul><sub id='5Az9e'></sub></form><legend id='5Az9e'></legend><bdo id='5Az9e'><pre id='5Az9e'><center id='5Az9e'></center></pre></bdo></b><th id='5Az9e'></th></span></q></dt></tr></i><div id='5Az9e'><tfoot id='5Az9e'></tfoot><dl id='5Az9e'><fieldset id='5Az9e'></fieldset></dl></div>
                  本文介绍了如何在没有 QProcess 的情况下将终端嵌入 PyQt5 应用程序中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我最近一直在努力在 PyQt GUI 应用程序中嵌入终端.几乎尝试了互联网上的所有搜索,但没有任何帮助.

                  I have been struggling lately with embedding a terminal inside PyQt GUI app. Tried almost every search on Internet but nothing looks like of any help.

                  我有一个 QTabWidget,我只需要一个标签就有一个终端.

                  I have a QTabWidget and I simply need one tab to have a terminal.

                  根本不可能这样做吗?

                  难道没有像 QTabWidget.Tab2.show(terminal-app) 这样的东西吗?默认终端会显示在 tab2 中,每个函数都像 lsifconfigcd 等工作正常吗?

                  Isn't there something like QTabWidget.Tab2.show(terminal-app) and default terminal gets displayed in tab2 and every function like ls, ifconfig, cd etc works fine ?

                  P.S - 我已经尝试过这些但没有成功.在 PyQt5 中嵌入终端

                  P.S - I have already tried these but no success. Embedding a terminal in PyQt5

                  (此处将代码从 PyQt4 转换为 PyQt5,但这不能满足我的需求)如何使用嵌入在 PyQt GUI 中的终端

                  (converted code here from PyQt4 to PyQt5 but this does not fulfill my needs) how to use a terminal embedded in a PyQt GUI

                  T.I.A

                  推荐答案

                  简答: Qt5不提供终端的使用,所以你必须使用QProcess.

                  short answer: Qt5 does not provide the use of the terminal, so you will have to use QProcess.

                  TL;DR

                  作为解决方案提出的 EmbTerminal 类是一个小部件,因此您必须使用 addTab() 添加它,请记住您必须已安装 urxvt 终端(如果你想检查你的安装在终端运行 urxvt)

                  The EmbTerminal class that is proposed as a solution is a widget so you must add it with addTab(), keep in mind that you must have installed the urxvt terminal (if you want to check your installation run urxvt in the terminal)

                  import sys
                  from PyQt5 import QtCore, QtWidgets
                  
                  
                  class EmbTerminal(QtWidgets.QWidget):
                      def __init__(self, parent=None):
                          super(EmbTerminal, self).__init__(parent)
                          self.process = QtCore.QProcess(self)
                          self.terminal = QtWidgets.QWidget(self)
                          layout = QtWidgets.QVBoxLayout(self)
                          layout.addWidget(self.terminal)
                          # Works also with urxvt:
                          self.process.start('urxvt',['-embed', str(int(self.winId()))])
                          self.setFixedSize(640, 480)
                  
                  
                  class mainWindow(QtWidgets.QMainWindow):
                      def __init__(self, parent=None):
                          super(mainWindow, self).__init__(parent)
                  
                          central_widget = QtWidgets.QWidget()
                          lay = QtWidgets.QVBoxLayout(central_widget)
                          self.setCentralWidget(central_widget)
                  
                          tab_widget = QtWidgets.QTabWidget()
                          lay.addWidget(tab_widget)
                  
                          tab_widget.addTab(EmbTerminal(), "EmbTerminal")
                          tab_widget.addTab(QtWidgets.QTextEdit(), "QTextEdit")
                          tab_widget.addTab(QtWidgets.QMdiArea(), "QMdiArea")
                  
                  
                  if __name__ == "__main__":
                      app = QtWidgets.QApplication(sys.argv)
                      main = mainWindow()
                      main.show()
                      sys.exit(app.exec_())
                  

                  这篇关于如何在没有 QProcess 的情况下将终端嵌入 PyQt5 应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:“QMessageBox.Yes"的替代方案对于 PyQt6 下一篇:如何在 PyQt5 中从鼠标到点画一条线?

                  相关文章

                  最新文章

                  <i id='SsjEU'><tr id='SsjEU'><dt id='SsjEU'><q id='SsjEU'><span id='SsjEU'><b id='SsjEU'><form id='SsjEU'><ins id='SsjEU'></ins><ul id='SsjEU'></ul><sub id='SsjEU'></sub></form><legend id='SsjEU'></legend><bdo id='SsjEU'><pre id='SsjEU'><center id='SsjEU'></center></pre></bdo></b><th id='SsjEU'></th></span></q></dt></tr></i><div id='SsjEU'><tfoot id='SsjEU'></tfoot><dl id='SsjEU'><fieldset id='SsjEU'></fieldset></dl></div>

                  <small id='SsjEU'></small><noframes id='SsjEU'>

                • <legend id='SsjEU'><style id='SsjEU'><dir id='SsjEU'><q id='SsjEU'></q></dir></style></legend>

                      <bdo id='SsjEU'></bdo><ul id='SsjEU'></ul>
                  1. <tfoot id='SsjEU'></tfoot>