Answer the question
In order to leave comments, you need to log in
Encountered an error while writing a command in QMessageBox. Who can advise?
I ran into a problem when adding a button to a QMessageBox
Here I will attach the code: (I marked the places of errors with #)
# Form implementation generated from reading ui file 'untitled.ui'
#
# Created by: PyQt6 UI code generator 6.0.0
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(247, 178)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(20, 20, 47, 13))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(20, 50, 47, 13))
self.label_2.setObjectName("label_2")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(80, 10, 113, 20))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(80, 50, 113, 20))
self.lineEdit_2.setObjectName("lineEdit_2")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(80, 100, 101, 21))
self.pushButton.setObjectName("pushButton")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 247, 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)
self.lineEdit.textChanged.connect(self.ChangeText)
self.lineEdit_2.textChanged.connect(self.ChangeText)
self.pushButton.clicked.connect(self.Result)
def Result (self):
try:
a=int(self.lineEdit.text())
if a>300:
a=a*0.1
b=int(self.lineEdit_2.text())
s=a*b
msg=QtWidgets.QMessageBox()
msg.setWindowTitle ('Идет подсчет...')
msg.setText('Вы сотрудник нашей фирмы?')
#Код перестает работать при добавлении нижней строки, не могу понять в чем проблема
#msg.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
msg.exec()
except:
msg= QtWidgets.QMessageBox()
msg.setWindowTitle ('Ошибка ввода!')
msg.setText('Ошибка ввода данных!')
if self.lineEdit.text()=='' or self.lineEdit_2.text ()== '':
msg.setInformativeText('Введите исходные данные.')
#Здесь такая же история
#msg.setIcon (QMessageBox.Warning)
msg.exec()
def ChangeText (self):
s = QtCore.QCoreApplication.instance().sender().text ()
for i in range(len (s) -1, -1, -1):
if not s[i].isdigit():
s=s[0:i] + s[i +1:len(s)]
break
QtCore.QCoreApplication.instance ().sender().setText(s)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label.setText(_translate("MainWindow", "Цена"))
self.label_2.setText(_translate("MainWindow", "Кол-во"))
self.pushButton.setText(_translate("MainWindow", "Стоймость"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec())
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow1()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec())
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question