With QTDesigner in version 5, I have done a mainwindow, now i like to create a QMessagebox on click on the Button in the mainwindow.
在版本5的QTDesigner中,我已经做了一个主窗口,现在我喜欢在主窗口的按钮上创建一个QMessagebox。
I got an error : argument 1 has unexpected type 'Ui_MainWindow'
我得到一个错误参数1的类型是" Ui_MainWindow "
I have no idea why this is not working, hopefully you can help me i'm really new to programming:
我不知道为什么这个不能工作,希望你能帮助我我真的是编程新手:
The line i added:
我添加的行:
self.pushButton.clicked.connect(QtWidgets.QMessageBox.information(self, "Empty String", "Please enter day."))
to:
:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(320, 240)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(210, 160, 75, 23))
self.pushButton.setObjectName("pushButton")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 320, 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)
self.pushButton.clicked.connect(QtWidgets.QMessageBox.information(self, "Empty String", "Please enter day."))
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "PushButton"))
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_())
1 个解决方案
#1
0
The correct number of spaces (called indentation) before every line is critical in Python. Enter 8 spaces before the line that you have added.
在Python中,在每一行之前正确的空格数(称为缩进)是至关重要的。在添加的行之前输入8个空格。
#1
0
The correct number of spaces (called indentation) before every line is critical in Python. Enter 8 spaces before the line that you have added.
在Python中,在每一行之前正确的空格数(称为缩进)是至关重要的。在添加的行之前输入8个空格。