Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How do I write the following pyqt5 .ui code as a pyqtconfig file?



  • Hi How do I write the following pyqt5 .ui code as a pyqtconfig file in python and if I want to update values for widgets how do I do this?

    from PyQt5 import QtCore, QtGui, QtWidgets
    
    class Ui_Laser(object):
        def setupUi(self, Laser):
            Laser.setObjectName("Laser")
            Laser.resize(379, 274)
            Laser.setMinimumSize(QtCore.QSize(379, 268))
            self.centralwidget = QtWidgets.QWidget(Laser)
            self.centralwidget.setObjectName("centralwidget")
            self.gridLayoutWidget = QtWidgets.QWidget(self.centralwidget)
            self.gridLayoutWidget.setGeometry(QtCore.QRect(0, 70, 371, 181))
            self.gridLayoutWidget.setObjectName("gridLayoutWidget")
            self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
            self.gridLayout.setContentsMargins(0, 0, 0, 0)
            self.gridLayout.setObjectName("gridLayout")
            self.spinBox_6 = QtWidgets.QSpinBox(self.gridLayoutWidget)
            self.spinBox_6.setMaximum(100)
            self.spinBox_6.setObjectName("spinBox_6")
            self.gridLayout.addWidget(self.spinBox_6, 1, 5, 1, 1)
            self.verticalSlider_2 = QtWidgets.QSlider(self.gridLayoutWidget)
            self.verticalSlider_2.setOrientation(QtCore.Qt.Vertical)
            self.verticalSlider_2.setObjectName("verticalSlider_2")
            self.gridLayout.addWidget(self.verticalSlider_2, 0, 1, 1, 1)
            self.verticalSlider_5 = QtWidgets.QSlider(self.gridLayoutWidget)
            self.verticalSlider_5.setOrientation(QtCore.Qt.Vertical)
            self.verticalSlider_5.setObjectName("verticalSlider_5")
            self.gridLayout.addWidget(self.verticalSlider_5, 0, 4, 1, 1)
            self.spinBox = QtWidgets.QSpinBox(self.gridLayoutWidget)
            self.spinBox.setMaximum(100)
            self.spinBox.setObjectName("spinBox")
            self.gridLayout.addWidget(self.spinBox, 1, 0, 1, 1)
            self.verticalSlider = QtWidgets.QSlider(self.gridLayoutWidget)
            self.verticalSlider.setOrientation(QtCore.Qt.Vertical)
            self.verticalSlider.setObjectName("verticalSlider")
            self.gridLayout.addWidget(self.verticalSlider, 0, 0, 1, 1)
            self.spinBox_2 = QtWidgets.QSpinBox(self.gridLayoutWidget)
            self.spinBox_2.setMaximum(100)
            self.spinBox_2.setObjectName("spinBox_2")
            self.gridLayout.addWidget(self.spinBox_2, 1, 1, 1, 1)
            self.verticalSlider_3 = QtWidgets.QSlider(self.gridLayoutWidget)
            self.verticalSlider_3.setOrientation(QtCore.Qt.Vertical)
            self.verticalSlider_3.setObjectName("verticalSlider_3")
            self.gridLayout.addWidget(self.verticalSlider_3, 0, 2, 1, 1)
            self.spinBox_5 = QtWidgets.QSpinBox(self.gridLayoutWidget)
            self.spinBox_5.setMaximum(100)
            self.spinBox_5.setObjectName("spinBox_5")
            self.gridLayout.addWidget(self.spinBox_5, 1, 4, 1, 1)
            self.verticalSlider_6 = QtWidgets.QSlider(self.gridLayoutWidget)
            self.verticalSlider_6.setOrientation(QtCore.Qt.Vertical)
            self.verticalSlider_6.setObjectName("verticalSlider_6")
            self.gridLayout.addWidget(self.verticalSlider_6, 0, 5, 1, 1)
            self.spinBox_4 = QtWidgets.QSpinBox(self.gridLayoutWidget)
            self.spinBox_4.setMaximum(100)
            self.spinBox_4.setObjectName("spinBox_4")
            self.gridLayout.addWidget(self.spinBox_4, 1, 3, 1, 1)
            self.verticalSlider_4 = QtWidgets.QSlider(self.gridLayoutWidget)
            self.verticalSlider_4.setOrientation(QtCore.Qt.Vertical)
            self.verticalSlider_4.setObjectName("verticalSlider_4")
            self.gridLayout.addWidget(self.verticalSlider_4, 0, 3, 1, 1)
            self.verticalSlider_7 = QtWidgets.QSlider(self.gridLayoutWidget)
            self.verticalSlider_7.setOrientation(QtCore.Qt.Vertical)
            self.verticalSlider_7.setObjectName("verticalSlider_7")
            self.gridLayout.addWidget(self.verticalSlider_7, 0, 6, 1, 1)
            self.spinBox_3 = QtWidgets.QSpinBox(self.gridLayoutWidget)
            self.spinBox_3.setMaximum(100)
            self.spinBox_3.setObjectName("spinBox_3")
            self.gridLayout.addWidget(self.spinBox_3, 1, 2, 1, 1)
            self.pushButton = QtWidgets.QPushButton(self.centralwidget)
            self.pushButton.setGeometry(QtCore.QRect(0, 50, 41, 19))
            self.pushButton.setCheckable(True)
            self.pushButton.setObjectName("pushButton")
            self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
            self.pushButton_2.setGeometry(QtCore.QRect(50, 50, 41, 19))
            self.pushButton_2.setCheckable(True)
            self.pushButton_2.setObjectName("pushButton_2")
            self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
            self.pushButton_3.setGeometry(QtCore.QRect(110, 50, 41, 19))
            self.pushButton_3.setCheckable(True)
            self.pushButton_3.setObjectName("pushButton_3")
            self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
            self.pushButton_4.setGeometry(QtCore.QRect(160, 50, 41, 19))
            self.pushButton_4.setCheckable(True)
            self.pushButton_4.setObjectName("pushButton_4")
            self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
            self.pushButton_5.setGeometry(QtCore.QRect(220, 50, 41, 19))
            self.pushButton_5.setCheckable(True)
            self.pushButton_5.setObjectName("pushButton_5")
            self.pushButton_6 = QtWidgets.QPushButton(self.centralwidget)
            self.pushButton_6.setGeometry(QtCore.QRect(270, 50, 41, 19))
            self.pushButton_6.setCheckable(True)
            self.pushButton_6.setObjectName("pushButton_6")
            self.pushButton_7 = QtWidgets.QPushButton(self.centralwidget)
            self.pushButton_7.setGeometry(QtCore.QRect(330, 50, 41, 19))
            self.pushButton_7.setCheckable(True)
            self.pushButton_7.setObjectName("pushButton_7")
            self.label = QtWidgets.QLabel(self.centralwidget)
            self.label.setGeometry(QtCore.QRect(0, 40, 39, 11))
            self.label.setObjectName("label")
            self.label_2 = QtWidgets.QLabel(self.centralwidget)
            self.label_2.setGeometry(QtCore.QRect(50, 40, 39, 11))
            self.label_2.setObjectName("label_2")
            self.label_3 = QtWidgets.QLabel(self.centralwidget)
            self.label_3.setGeometry(QtCore.QRect(110, 40, 39, 11))
            self.label_3.setObjectName("label_3")
            self.label_4 = QtWidgets.QLabel(self.centralwidget)
            self.label_4.setGeometry(QtCore.QRect(160, 40, 39, 11))
            self.label_4.setObjectName("label_4")
            self.label_5 = QtWidgets.QLabel(self.centralwidget)
            self.label_5.setGeometry(QtCore.QRect(220, 40, 39, 11))
            self.label_5.setObjectName("label_5")
            self.label_6 = QtWidgets.QLabel(self.centralwidget)
            self.label_6.setGeometry(QtCore.QRect(270, 40, 39, 11))
            self.label_6.setObjectName("label_6")
            self.label_7 = QtWidgets.QLabel(self.centralwidget)
            self.label_7.setGeometry(QtCore.QRect(330, 40, 39, 11))
            self.label_7.setObjectName("label_7")
            self.pushButton_8 = QtWidgets.QPushButton(self.centralwidget)
            self.pushButton_8.setGeometry(QtCore.QRect(10, 10, 62, 19))
            self.pushButton_8.setCheckable(True)
            self.pushButton_8.setChecked(True)
            self.pushButton_8.setObjectName("pushButton_8")
            Laser.setCentralWidget(self.centralwidget)
            self.statusbar = QtWidgets.QStatusBar(Laser)
            self.statusbar.setObjectName("statusbar")
            Laser.setStatusBar(self.statusbar)
    
            self.retranslateUi(Laser)
            self.spinBox.valueChanged['int'].connect(self.verticalSlider.setValue)
            self.spinBox_2.valueChanged['int'].connect(self.verticalSlider_2.setValue)
            self.spinBox_3.valueChanged['int'].connect(self.verticalSlider_3.setValue)
            self.spinBox_4.valueChanged['int'].connect(self.verticalSlider_4.setValue)
            self.spinBox_5.valueChanged['int'].connect(self.verticalSlider_5.setValue)
            self.spinBox_6.valueChanged['int'].connect(self.verticalSlider_6.setValue)
            QtCore.QMetaObject.connectSlotsByName(Laser)
    
        def retranslateUi(self, Laser):
            _translate = QtCore.QCoreApplication.translate
            Laser.setWindowTitle(_translate("Laser", "MainWindow"))
            self.pushButton.setText(_translate("Laser", "ON"))
            self.pushButton_2.setText(_translate("Laser", "ON"))
            self.pushButton_3.setText(_translate("Laser", "ON"))
            self.pushButton_4.setText(_translate("Laser", "ON"))
            self.pushButton_5.setText(_translate("Laser", "ON"))
            self.pushButton_6.setText(_translate("Laser", "ON"))
            self.pushButton_7.setText(_translate("Laser", "ON"))
            self.label.setText(_translate("Laser", "445nm"))
            self.label_2.setText(_translate("Laser", "488nm"))
            self.label_3.setText(_translate("Laser", "515nm"))
            self.label_4.setText(_translate("Laser", "561nm"))
            self.label_5.setText(_translate("Laser", "594nm"))
            self.label_6.setText(_translate("Laser", "638nm"))
            self.label_7.setText(_translate("Laser", "LED"))
            self.pushButton_8.setText(_translate("Laser", "ON"))
    
    if __name__ == "__main__":
        import sys
        app = QtWidgets.QApplication(sys.argv)
        Laser = QtWidgets.QMainWindow()
        ui = Ui_Laser()
        ui.setupUi(Laser)
        Laser.show()
        sys.exit(app.exec_())
    

    Thanks



  • @sdf1444 said in How do I write the following pyqt5 .ui code as a pyqtconfig file?:

    .ui code

    As a side note, such extension is used in Qt for XML files describing the GUI that you usually create graphically with Qt Designer.
    Later on such GUI definitions are converted into code by code generators:

    1. .h/.cpp files -> uic
    2. .py files -> pyside-uic

    The snippet you posted is a programatically created GUI...



  • @Pablo-J-Rogina
    Ok thanks. But can you help me with my problem?

    Thanks


  • Banned

    I could help you with the problem but it would be a two-fold solution -- the first part would be to show you how to create pyqt code the way it was meant to be used (without that garbage you get from the Designer) and then once you understand that why having it in a config file would make no sense



  • @Denni-0

    Hi

    I would much appreciate it if I can get the help for this.

    Regards


  • Banned

    Okay if you can get on Discord drop me a message and I will give you an invite to you Free Tutoring message server where I am already helping numerous folks with understanding python/pyqt and they are in turn helping some of the others that joined later -- DenniO#8137


Log in to reply