GamerDisclaimer
@GamerDisclaimer
Scratch Программист XD

PySide не показывается окно, как решить проблему?

Всем привет народ!
Недавно перешел с tkinter на pyside2, и столкнулся с проблемами. Код никаких ошибок не выдаёт, но окно не запускается.

Вот код дизайна:
# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'design.ui'
##
## Created by: Qt User Interface Compiler version 5.15.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *


class Ui_HackCSGO(object):
    def setupUi(self, HackCSGO):
        if not HackCSGO.objectName():
            HackCSGO.setObjectName(u"HackCSGO")
        HackCSGO.setWindowModality(Qt.NonModal)
        HackCSGO.resize(726, 514)
        HackCSGO.setMinimumSize(QSize(726, 514))
        HackCSGO.setMaximumSize(QSize(726, 514))
        font = QFont()
        font.setFamily(u"Segoe UI")
        font.setPointSize(10)
        HackCSGO.setFont(font)
        HackCSGO.setCursor(QCursor(Qt.CrossCursor))
        HackCSGO.setContextMenuPolicy(Qt.NoContextMenu)
        icon = QIcon()
        iconThemeName = u"CS"
        if QIcon.hasThemeIcon(iconThemeName):
            icon = QIcon.fromTheme(iconThemeName)
        else:
            icon.addFile(u"icon.png", QSize(), QIcon.Normal, QIcon.Off)
        
        HackCSGO.setWindowIcon(icon)
        HackCSGO.setStyleSheet(u"QLabel {\n"
"font: 18pt \"Consolas\";\n"
"}")
        self.centralwidget = QWidget(HackCSGO)
        self.centralwidget.setObjectName(u"centralwidget")
        self.label = QLabel(self.centralwidget)
        self.label.setObjectName(u"label")
        self.label.setGeometry(QRect(10, 10, 711, 71))
        self.label.setStyleSheet(u"QLabel {\n"
"	font: 87 45pt \"Fulbo\";\n"
"}")
        self.label.setTextFormat(Qt.AutoText)
        self.label.setAlignment(Qt.AlignCenter)
        self.label.setWordWrap(False)
        self.label.setOpenExternalLinks(False)
        self.pushButton = QPushButton(self.centralwidget)
        self.pushButton.setObjectName(u"pushButton")
        self.pushButton.setGeometry(QRect(10, 420, 581, 31))
        self.pushButton_2 = QPushButton(self.centralwidget)
        self.pushButton_2.setObjectName(u"pushButton_2")
        self.pushButton_2.setGeometry(QRect(600, 420, 111, 31))
        self.formLayoutWidget = QWidget(self.centralwidget)
        self.formLayoutWidget.setObjectName(u"formLayoutWidget")
        self.formLayoutWidget.setGeometry(QRect(10, 89, 701, 321))
        self.formLayout = QFormLayout(self.formLayoutWidget)
        self.formLayout.setObjectName(u"formLayout")
        self.formLayout.setContentsMargins(0, 0, 0, 0)
        self.label_2 = QLabel(self.formLayoutWidget)
        self.label_2.setObjectName(u"label_2")

        self.formLayout.setWidget(0, QFormLayout.LabelRole, self.label_2)

        self.lineEdit = QLineEdit(self.formLayoutWidget)
        self.lineEdit.setObjectName(u"lineEdit")

        self.formLayout.setWidget(0, QFormLayout.FieldRole, self.lineEdit)

        self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.formLayout.setItem(1, QFormLayout.SpanningRole, self.verticalSpacer)

        self.label_3 = QLabel(self.formLayoutWidget)
        self.label_3.setObjectName(u"label_3")

        self.formLayout.setWidget(2, QFormLayout.LabelRole, self.label_3)

        self.checkBox = QCheckBox(self.formLayoutWidget)
        self.checkBox.setObjectName(u"checkBox")
        font1 = QFont()
        font1.setFamily(u"Consolas")
        font1.setPointSize(12)
        self.checkBox.setFont(font1)
        self.checkBox.setTristate(False)

        self.formLayout.setWidget(2, QFormLayout.FieldRole, self.checkBox)

        self.verticalSpacer_2 = QSpacerItem(20, 10, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.formLayout.setItem(3, QFormLayout.SpanningRole, self.verticalSpacer_2)

        self.label_4 = QLabel(self.formLayoutWidget)
        self.label_4.setObjectName(u"label_4")

        self.formLayout.setWidget(4, QFormLayout.LabelRole, self.label_4)

        self.checkBox_2 = QCheckBox(self.formLayoutWidget)
        self.checkBox_2.setObjectName(u"checkBox_2")

        self.formLayout.setWidget(4, QFormLayout.FieldRole, self.checkBox_2)

        self.verticalSpacer_4 = QSpacerItem(20, 10, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.formLayout.setItem(5, QFormLayout.SpanningRole, self.verticalSpacer_4)

        self.label_5 = QLabel(self.formLayoutWidget)
        self.label_5.setObjectName(u"label_5")

        self.formLayout.setWidget(6, QFormLayout.LabelRole, self.label_5)

        self.checkBox_3 = QCheckBox(self.formLayoutWidget)
        self.checkBox_3.setObjectName(u"checkBox_3")

        self.formLayout.setWidget(6, QFormLayout.FieldRole, self.checkBox_3)

        self.verticalSpacer_3 = QSpacerItem(20, 10, QSizePolicy.Minimum, QSizePolicy.Expanding)

        self.formLayout.setItem(7, QFormLayout.SpanningRole, self.verticalSpacer_3)

        self.label_6 = QLabel(self.formLayoutWidget)
        self.label_6.setObjectName(u"label_6")

        self.formLayout.setWidget(8, QFormLayout.LabelRole, self.label_6)

        self.checkBox_4 = QCheckBox(self.formLayoutWidget)
        self.checkBox_4.setObjectName(u"checkBox_4")

        self.formLayout.setWidget(8, QFormLayout.FieldRole, self.checkBox_4)

        HackCSGO.setCentralWidget(self.centralwidget)
        self.statusbar = QStatusBar(HackCSGO)
        self.statusbar.setObjectName(u"statusbar")
        HackCSGO.setStatusBar(self.statusbar)

        self.retranslateUi(HackCSGO)

        QMetaObject.connectSlotsByName(HackCSGO)
    # setupUi

    def retranslateUi(self, HackCSGO):
        HackCSGO.setWindowTitle(QCoreApplication.translate("HackCSGO", u"HackCS:GO", None))
        self.label.setText(QCoreApplication.translate("HackCSGO", u"Hack CS:GO", None))
        self.pushButton.setText(QCoreApplication.translate("HackCSGO", u"Hack", None))
        self.pushButton_2.setText(QCoreApplication.translate("HackCSGO", u"Abort", None))
        self.label_2.setText(QCoreApplication.translate("HackCSGO", u"Steam of user:", None))
        self.label_3.setText(QCoreApplication.translate("HackCSGO", u"Wallhack", None))
        self.checkBox.setText("")
        self.label_4.setText(QCoreApplication.translate("HackCSGO", u"AIM Bot", None))
        self.checkBox_2.setText("")
        self.label_5.setText(QCoreApplication.translate("HackCSGO", u"SkinChanger", None))
        self.checkBox_3.setText("")
        self.label_6.setText(QCoreApplication.translate("HackCSGO", u"Unlimited Health", None))
        self.checkBox_4.setText("")
    # retranslateUi


Вот код главного файла main.py:
import sys
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from design import *

# Новый экземпляр QApplication
app = QApplication(sys.argv)
sys.exit(app.exec_())


Код ошибок не выдаёт, но окно не запускается
5fd0c1ca9a148330691342.png

Если не лень, то помогите, буду очень благодарен
  • Вопрос задан
  • 257 просмотров
Решения вопроса 1
GamerDisclaimer
@GamerDisclaimer Автор вопроса
Scratch Программист XD
Нашёл решение!
Если кому-то нужен будет ответ, то вот решение:
В файле main.py я не инициализировал окно.
Я заменил весь код в нём на такой:
import sys
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
from design import *

# Новый экземпляр QApplication
app = QApplication(sys.argv)
Window = QMainWindow()
my_window = Ui_HackCSGO()
my_window.setupUi(Window)
Window.show()
sys.exit(app.exec_())

И всё заработало
5fd0c9df8e8d0426153263.png
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы