T
T
Timosia2019-10-10 15:54:28
Python
Timosia, 2019-10-10 15:54:28

Why is there no if __name__ == "__main__" when translating .ui to .py?

When I want to translate .ui to .py , there is no if __name__ == "__main__" present in my code. Tried to re-translate ui to py , but if __name__ == "__main__" is missing again.

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(240, 281)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 240, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(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"))

PS Already tried to reinstall PyQt
PS Yes I know I can use the loadUI() function from uic

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-10-10
@Timosia

Because you don't need the construct in the library file, it's only for the main executable. if __name__ == "__main__":

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question