O
O
ObehanProger2019-06-26 10:53:44
PyQt
ObehanProger, 2019-06-26 10:53:44

Why can't I start the terminal by pressing a button in the application?

When you click on the "run" button, a terminal should open and execute the ls -l command. But the button doesn't work. Here is the main application code main.py:

import sys
from PyQt5.QtWidgets import QWidget, QPushButton, QApplication
from PyQt5.QtCore import QCoreApplication
import os, subprocess

class Example(QWidget):

    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        qbtn = QPushButton('Выполнить', self)
        qbtn.clicked.connect(self.btnClicked)
        qbtn.resize(qbtn.sizeHint())
        qbtn.move(50, 50)
        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle('Quit button')
        self.show()

    def btnClicked():
        subprocess.Popen(['xterm', '-hold', '-e', 'ls -ahl'])

if __name__ == '__main__':

    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Q
qlkvg, 2019-06-26
@qlkvg

And from what you should open the terminal then? You need to open a terminal emulator first, and then execute console commands.

subprocess.Popen(['xterm', '-hold', '-e', 'ls -ahl'])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question