Answer the question
In order to leave comments, you need to log in
How to run from ui (Pyqt5) to py in Python?
How can I make this script run in such a way?
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'TEST5.ui'
#
# Created by: PyQt5 UI code generator 5.15.0
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(358, 403)
Form.setStyleSheet("QPushButton{\n"
" badground -color:white\n"
"width: 70px\n"
"height:
" font-size: 12px\n"
" fond-weight: bold\n"
" border: none\n"
" text-algn: center\n"
"}")
self.gridLayoutWidget = QtWidgets.QWidget(Form)
self. gridLayoutWidget.setGeometry(QtCore.QRect(40, 140, 271, 241))
self.gridLayoutWidget.setObjectName("gridLayoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.gridLayoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0 , 0)
self.gridLayout.setObjectName("gridLayout")
self.pushButton_5 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_5.setObjectName("pushButton_5")
self.gridLayout.addWidget(self.pushButton_5, 2, 0, 1, 1)
self.pushButton_12 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_12.setObjectName("pushButton_12")
self.gridLayout.addWidget(self.pushButton_12, 4, 1, 1, 1)
self.pushButton_4 = QtWidgets.QPushButton(self. gridLayoutWidget)
self.pushButton_4.setObjectName("pushButton_4")
self.gridLayout.addWidget(self.pushButton_4, 0, 0, 1, 1)
self.pushButton_8 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_8.setObjectName("pushButton_8 ")
self.gridLayout.addWidget(self.pushButton_8, 2, 2, 1, 1)
self.pushButton_9 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_9.setObjectName("pushButton_9")
self.gridLayout.addWidget(self.pushButton_9, 3, 1, 1, 1)
self.pushButton_6 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_6.setObjectName("pushButton_6")
self.gridLayout.addWidget(self.pushButton_6, 3, 0, 1, 1)
self.pushButton_10 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_10.setObjectName("pushButton_10")
self.gridLayout.addWidget(self.pushButton_10, 3, 2, 1, 1)
self. pushButton_13 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_13.setObjectName("pushButton_13")
self.gridLayout.addWidget(self.pushButton_13, 4, 2, 1, 1)
self.pushButton_2 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_2.setObjectName("pushButton_2")
self.gridLayout.addWidget(self.pushButton_2, 0, 2, 1, 1)
self.pushButton_7 = QtWidgets.QPushButton(self. gridLayoutWidget)
self.pushButton_7.setObjectName("pushButton_7")
self.gridLayout.addWidget(self.pushButton_7, 2, 1, 1, 1)
self.pushButton_11 = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton_11.setObjectName("pushButton_11 ")
self.gridLayout.addWidget(self.pushButton_11, 4, 0, 1, 1)
self.pushButton = QtWidgets.QPushButton(self.gridLayoutWidget)
self.pushButton.setObjectName("pushButton")
self.gridLayout.addWidget(self.pushButton, 0, 1, 1, 1)
self.gridLayoutWidget_2 = QtWidgets.QWidget(Form)
self.gridLayoutWidget_2.setGeometry(QtCore.QRect(40, 100, 271, 41))
self.gridLayoutWidget_2 .setObjectName("gridLayoutWidget_2")
self.gridLayout_2 = QtWidgets.QGridLayout(self.gridLayoutWidget_2)
self.gridLayout_2.setContentsMargins(0, 0, 0, 0)
self.gridLayout_2.setObjectName("gridLayout_2")
self.pushButton_3 = QtWidgets.QPushButton (self.gridLayoutWidget_2)
self.pushButton_3.setObjectName("pushButton_3")
self.gridLayout_2.addWidget(self.pushButton_3, 0, 0, 1, 1)
self.pushButton_14 = QtWidgets.QPushButton(self.gridLayoutWidget_2)
self.pushButton_14.setObjectName("pushButton_14")
self.gridLayout_2.addWidget(self.pushButton_14, 0, 1, 1, 1)
self.lineEdit = QtWidgets.QLineEdit(Form)
self.lineEdit.setGeometry(QtCore.QRect(40, 40, 271, 41))
self.lineEdit.setObjectName("lineEdit")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form) :
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton_5.setText(_translate("Form", "4"))
self.pushButton_12.setText(_translate("Form", "0"))
self.pushButton_4.setText(_translate("Form", "1"))
self.pushButton_8.setText(_translate("Form", "6") )
self.pushButton_9.setText(_translate("Form", "8"))
self.pushButton_6.setText(_translate("Form", "7"))
self.pushButton_10.setText(_translate("Form", "9" ))
self.pushButton_13.setText(_translate("Form", "+"))
self.pushButton_2.setText(_translate("Form", "3"))
self.pushButton_7.setText(_translate("Form", "5 "))
self.pushButton_11.setText(_translate("Form", "-"))
self.pushButton.setText(_translate("Form", "2"))
self.pushButton_3.setText(_translate("Form", "*"))
self.pushButton_14.setText(_translate("Form", "/"))
Answer the question
In order to leave comments, you need to log in
You need to create a class that inherits from QMainWindow and your form, you also need to call setupUi. Next, run as a normal PyQt application:
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
from Ui_Form import Ui_Form # Замените на импорт вашего класса
class MainWindow(QMainWindow, Ui_Form):
def __init__(self):
super().__init__()
self.setupUi()
app = QApplication(sys.argv)
main_window = MainWindow()
main_window.show()
sys.exit(app.exec_())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question