I already complete embedded terminal to PyQt5 application follow this answer.
Now I want to use buttons to send command to this embedded terminal similar here.
Ex:
Button_1 send "ifconfig",
Button_2 send "ping 127.0.0.1".
My code:
import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QPushButton
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.process.start('xterm',['-into', str(int(self.winId()))])
# self.setFixedSize(640, 480)
button1 = QPushButton('ifconfig')
layout.addWidget(button1)
button1.clicked.connect(self.button_1_clicked)
button2 = QPushButton('ping 127.0.0.1')
layout.addWidget(button2)
button2.clicked.connect(self.button_2_clicked)
def button_1_clicked(self):
print('send \"ifconfig\" to embedded termial')
def button_2_clicked(self):
print('send \"ping 127.0.0.1\" to embedded termial')
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_())
How can I do it?
I already tried other answer(attach another application to PyQt5 window) and answer(pass command to QProcess C++ not Python)
One possible solution is to use
tmux
as an intermediary to send the commands: