Сконвеотировал Qt в py но когда я запускаю ошибки не выводится но и окно не появляется
Я сконвертировал .ui в .py, но когда я запускаю ошибки не выводится, но и окно не появляется
Код 1-го файла, который сконвертировался из .ui:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'D:\Programs\Wheather.ui'
#
# Created by: PyQt5 UI code generator 5.14.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(406, 499)
Dialog.setStyleSheet("background-color: rgb(79, 79, 79);")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(130, 100, 141, 51))
self.pushButton.setStyleSheet("QPushButton{\n"
"color:rgb(255, 174, 0);\n"
"font: 24pt \"MV Boli\";\n"
"background-color: rgb(31, 31, 31);\n"
"}\n"
"\n"
"\n"
"QPushButton:hover{\n"
" background-color:rgb(79, 79, 79);\n"
" color:rgb(234, 156, 0);\n"
"}\n"
"\n"
"\n"
"\n"
"QPushButton:pressed{\n"
" color:rgb(255, 226, 0)\n"
"\n"
"}\n"
"")
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(0, 160, 401, 151))
self.label.setStyleSheet("color:red;\n"
"background-color:(31, 31, 31);\n"
"font: 12pt \"Fixedsys\";\n"
"font-size: 30px;")
self.label.setText("")
self.label.setObjectName("label")
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(20, 30, 361, 61))
self.lineEdit.setStyleSheet("color:rgb(255, 174, 0);\n"
"background-color:(31, 31, 31) ;\n"
"font: 75 italic 26pt \"Palatino Linotype\";\n"
"border-color: rgb(41, 141, 13);\n"
"")
self.lineEdit.setObjectName("lineEdit")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.pushButton.setText(_translate("Dialog", "GIVE"))
А вот что сделал я:
from PySide2 import QtCore, QtGui, QtWidgets
import sys
import pyowm
from wheather import Ui_Dialog
app = QtWidgets.QApplication(sys.argv)
win = uic.loadUi("Wheather.ui")
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
Ответы (1 шт):
Автор решения: S. Nick
→ Ссылка
Как вариант. Если у вас PySide2 поставьте свои импорты.
import sys
#import pyowm
from PyQt5 import QtCore, QtGui, QtWidgets, uic
#from PySide2 import QtCore, QtGui, QtWidgets
#from wheather import Ui_Dialog
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(406, 499)
Dialog.setStyleSheet("background-color: rgb(79, 79, 79);")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(130, 100, 141, 51))
self.pushButton.setStyleSheet("QPushButton{\n"
"color:rgb(255, 174, 0);\n"
"font: 24pt \"MV Boli\";\n"
"background-color: rgb(31, 31, 31);\n"
"}\n"
"\n"
"\n"
"QPushButton:hover{\n"
" background-color:rgb(79, 79, 79);\n"
" color:rgb(234, 156, 0);\n"
"}\n"
"\n"
"\n"
"\n"
"QPushButton:pressed{\n"
" color:rgb(255, 226, 0)\n"
"\n"
"}\n"
"")
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(0, 160, 401, 151))
self.label.setStyleSheet("color:red;\n"
"background-color:(31, 31, 31);\n"
"font: 12pt \"Fixedsys\";\n"
"font-size: 30px;")
self.label.setText("")
self.label.setObjectName("label")
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(20, 30, 361, 61))
self.lineEdit.setStyleSheet("color:rgb(255, 174, 0);\n"
"background-color:(31, 31, 31) ;\n"
"font: 75 italic 26pt \"Palatino Linotype\";\n"
"border-color: rgb(41, 141, 13);\n"
"")
self.lineEdit.setObjectName("lineEdit")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.pushButton.setText(_translate("Dialog", "GIVE"))
class Dialog(QtWidgets.QDialog, Ui_Dialog):
def __init__(self):
super().__init__()
self.setupUi(self)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
# win = uic.loadUi("Wheather.ui")
w = Dialog()
# ui = Ui_Dialog()
# ui.setupUi(Dialog)
w.show()
sys.exit(app.exec_())
Update 1
Вариант 2
main.py
import sys
#import pyowm
from PyQt5 import QtCore, QtGui, QtWidgets, uic
#from PySide2 import QtCore, QtGui, QtWidgets
from wheather import Ui_Dialog
class Dialog(QtWidgets.QDialog, Ui_Dialog):
def __init__(self):
super().__init__()
self.setupUi(self)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
# win = uic.loadUi("Wheather.ui")
w = Dialog()
# ui = Ui_Dialog()
# ui.setupUi(Dialog)
w.show()
sys.exit(app.exec_())
wheather.py
from PyQt5 import QtCore, QtGui, QtWidgets
#from PySide2 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(406, 499)
Dialog.setStyleSheet("background-color: rgb(79, 79, 79);")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(130, 100, 141, 51))
self.pushButton.setStyleSheet("QPushButton{\n"
"color:rgb(255, 174, 0);\n"
"font: 24pt \"MV Boli\";\n"
"background-color: rgb(31, 31, 31);\n"
"}\n"
"\n"
"\n"
"QPushButton:hover{\n"
" background-color:rgb(79, 79, 79);\n"
" color:rgb(234, 156, 0);\n"
"}\n"
"\n"
"\n"
"\n"
"QPushButton:pressed{\n"
" color:rgb(255, 226, 0)\n"
"\n"
"}\n"
"")
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(0, 160, 401, 151))
self.label.setStyleSheet("color:red;\n"
"background-color:(31, 31, 31);\n"
"font: 12pt \"Fixedsys\";\n"
"font-size: 30px;")
self.label.setText("")
self.label.setObjectName("label")
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(20, 30, 361, 61))
self.lineEdit.setStyleSheet("color:rgb(255, 174, 0);\n"
"background-color:(31, 31, 31) ;\n"
"font: 75 italic 26pt \"Palatino Linotype\";\n"
"border-color: rgb(41, 141, 13);\n"
"")
self.lineEdit.setObjectName("lineEdit")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.pushButton.setText(_translate("Dialog", "GIVE"))
