PyQt is a library that lets you use the Qt GUI framework from Python. Qt itself is written in C++. By using it from Python, you can build applications much more quickly while not sacrificing much of the speed of C++.
PyQt5 refers to the most recent version 5 of Qt. You may still find the occasional mention of (Py)Qt4 on the web, but it is old and no longer supported.
from PyQt5.QtWidgets import QApplication, QLabel
- The QApplication class manages the GUI application’s control flow and main settings.
- A QLabel object acts as a placeholder to display non-editable text or image, or a movie of animated GIF.
This is a requirement of Qt: Every GUI app must have exactly one instance of QApplication. Many parts of Qt don’t work until you have executed the above line. You will therefore need it in virtually every (Py)Qt app you write.
app = QApplication([])
The brackets [] in the above line represent the command line arguments passed to the application. Because our app doesn’t use any parameters, we leave the brackets empty.
label = QLabel('Hello World!')
label.show()
designer &
- Create two PlainTextFields for taking input and showing output
- Create a push button to run the command
python3 -m PyQt5.uic.pyuic -x xml.ui -o output.py
python3 output.py
self.pushButton.clicked.connect(self.run_command())
def run_command(self):
txt = str(self.plainTextEdit_input.toPlainText())
process = subprocess.Popen(
txt, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
out,err = process.communicate()
self.plainTextEdit_output.insertPlainText(str(out,"utf-8"))