I have a problem opening a file with Qt Designer. When I try to open a program without a class, everything is fine, but when I try to open a program with a class, the program works, but nothing is displayed in the console and the program does not open.
Please help me.
import sys
from PySide6.QtWidgets import QApplication, QMainWindow
from PySide6.QtUiTools import QUiLoader
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
loader = QUiLoader()
self.window = loader.load('project2.ui', None)
self.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
sys.exit(app.exec())
The above program doesn’t work, but the one below does.
import sys
from PySide6.QtWidgets import QApplication, QMainWindow
from PySide6.QtUiTools import QUiLoader
loader = QUiLoader()
app = QApplication(sys.argv)
window = loader.load('project2.ui', None)
window.show()
app.exec()
New contributor
user26623307 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.