In this PyQt6 article we want to learn How to Convert PyQt6 Designer UI to PY File, so we already have talked that Qt Designer is part of the Qt framework, which is widely used for developing cross platform applications with graphical user interfaces. Qt Designer provides a drag and drop interface for designing UI layouts and arranging widgets, and this makes it accessible to developers of all skill levels.
How to Convert PyQt6 Designer UI to PY File
To convert Qt Designer UI file to PY file, first you should design your PyQt6 GUI Application with Qt Designer, i already have a lesson on PyQt6 Qt Designer, you can check that.
Open your Qt Designer, we have created this simple design and we want to convert that to Python file, that we can execute and run the code.
First of all you need to save your file, the file extension will be .ui, i have saved the file at name of mywindow.ui.
Now you can use this command to convert your Qt Designer UI file to Python PY file.
1 |
pyuic6 -x mywindow.ui -o mywindow.py |
Now our file is converted and this will be the result.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# Form implementation generated from # reading ui file 'mywindow.ui' # # Created by: PyQt6 UI code generator 6.4.2 # # WARNING: Any manual changes made to this # file will be lost when pyuic6 is # run again. Do not edit this file unless # you know what you are doing. from PyQt6 import QtCore, QtGui, QtWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(519, 394) self.centralwidget = QtWidgets.QWidget(parent=MainWindow) self.centralwidget.setObjectName("centralwidget") self.pushButton = QtWidgets.QPushButton(parent=self.centralwidget) self.pushButton.setGeometry(QtCore.QRect(80, 80, 75, 24)) self.pushButton.setObjectName("pushButton") self.label = QtWidgets.QLabel(parent=self.centralwidget) self.label.setGeometry(QtCore.QRect(80, 160, 311, 71)) font = QtGui.QFont() font.setPointSize(18) self.label.setFont(font) self.label.setObjectName("label") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(parent=MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 519, 22)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(parent=MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.pushButton.setText(_translate("MainWindow", "Codeloop")) self.label.setText(_translate("MainWindow", "Welcome to Codeloop.org")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec()) |
Run the code and this will be the result
FAQs
Q: What is PyQt6 Designer UI file?
A: PyQt6 Designer UI file is an XML-based file generated by Qt Designer, which contains the layout and properties of the user interface designed using Qt Designer. This file typically has a .ui extension.
Q: Why do I need to convert PyQt6 Designer UI file to Python code?
A: Converting PyQt6 Designer UI file to Python code allows you to integrate the UI design into your PyQt6 application. Python code generated from UI file instantiates the UI components and defines their properties and behavior, and this makes them usable within your Python application.
Q: How do I convert a PyQt6 Designer UI file to Python code?
A: You can convert PyQt6 Designer UI file to Python code using pyuic6 command-line utility provided by PyQt6. Run pyuic6 -x input.ui -o output.py in the terminal or command prompt, replacing input.ui with the path to your UI file and output.py with the desired name for the Python file.
Learn More on PyQt6:
- How to Install PyQt6
- PyQt6 Window Type Classes
- How to Add Title and Icon in PyQt6
- Qt Designer in PyQt6
Subscribe and Get Free Video Courses & Articles in your Email