Pyqt4年龄计算器未在标签上输出

时间:2019-03-07 07:16:16

标签: python pyqt pyqt4 calculator

我的python / QT(Pyqt4)程序应该在按下计算按钮后输出一个人的年龄,但事实并非如此,我哪里出错了。特此附上我的程序运行时的代码和屏幕截图。 我的python代码未在标签中显示文本。

这是我的.pyw文件

import sys
from ass2q2 import *

class MyForm(QtGui.QDialog):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        QtCore.QObject.connect(self.ui.calculateBtn, QtCore.SIGNAL('clicked()'),self.dispmessage)

    def dispmessage(self):
        bd=(self.ui.calBD.selectedDate())
        curr= QDate.currentDate()
        yourAge = bd.daysTo(curr)        
        self.ui.labelOutput.setText("Your Age (in days) is: " +yourAge.toString())


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    myapp = MyForm()
    myapp.show()
    sys.exit(app.exec_())

ass2q2.py文件

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'ass2q2.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName(_fromUtf8("Dialog"))
        Dialog.resize(705, 531)
        self.calBD = QtGui.QCalendarWidget(Dialog)
        self.calBD.setGeometry(QtCore.QRect(40, 150, 280, 155))
        self.calBD.setObjectName(_fromUtf8("calBD"))
        self.calCurr = QtGui.QCalendarWidget(Dialog)
        self.calCurr.setEnabled(False)
        self.calCurr.setGeometry(QtCore.QRect(370, 150, 280, 155))
        self.calCurr.setObjectName(_fromUtf8("calCurr"))
        self.labelbirth = QtGui.QLabel(Dialog)
        self.labelbirth.setGeometry(QtCore.QRect(40, 120, 271, 16))
        self.labelbirth.setObjectName(_fromUtf8("labelbirth"))
        self.labelToDate = QtGui.QLabel(Dialog)
        self.labelToDate.setGeometry(QtCore.QRect(380, 120, 261, 21))
        self.labelToDate.setObjectName(_fromUtf8("labelToDate"))
        self.labelOutput = QtGui.QLabel(Dialog)
        self.labelOutput.setGeometry(QtCore.QRect(60, 340, 581, 41))
        self.labelOutput.setLineWidth(3)
        self.labelOutput.setText(_fromUtf8(""))
        self.labelOutput.setObjectName(_fromUtf8("labelOutput"))
        self.calculateBtn = QtGui.QPushButton(Dialog)
        self.calculateBtn.setGeometry(QtCore.QRect(290, 460, 141, 51))
        self.calculateBtn.setObjectName(_fromUtf8("calculateBtn"))
        self.labelApp = QtGui.QLabel(Dialog)
        self.labelApp.setGeometry(QtCore.QRect(140, 60, 411, 41))
        self.labelApp.setObjectName(_fromUtf8("labelApp"))

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
        self.labelbirth.setText(_translate("Dialog", "<html><head/><body><p align=\"center\"><span style=\" font-weight:600;\">Select the Birth Date</span></p></body></html>", None))
        self.labelToDate.setText(_translate("Dialog", "<html><head/><body><p align=\"center\"><span style=\" font-weight:600;\">Current Date</span></p></body></html>", None))
        self.calculateBtn.setText(_translate("Dialog", "C A L C U L A T E", None))
        self.labelApp.setText(_translate("Dialog", "<html><head/><body><p align=\"center\"><span style=\" font-size:12pt; font-weight:600;\">AGE (in days) CALCULATOR</span></p></body></html>", None))



enter imsdfage description here

0 个答案:

没有答案