当运行python脚本导入代码以调用UI设计并显示时,我没有错误,但没有显示

时间:2019-02-22 10:20:44

标签: pyqt4

早上好,请有人帮忙,我必须在我的U.I中添加两个日历,一个生日日历和一个2019年日历。 当我运行python脚本时,我没有收到任何错误,没有任何反应。它不显示U.I设计。

第一个代码是将.ui转换为.py,之后的代码是调用和显示UI设计的代码,但是什么也没有发生,请有人帮帮我,我是Python的新手,我真的很挣扎。

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(704, 580)
        self.calendarWidget = QtGui.QCalendarWidget(Dialog)
        self.calendarWidget.setGeometry(QtCore.QRect(190, 10, 280, 155))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Script MT Bold"))
        font.setBold(True)
        font.setItalic(False)
        font.setWeight(75)
        self.calendarWidget.setFont(font)
        self.calendarWidget.setObjectName(_fromUtf8("calendarWidget"))
        self.calendarWidget_2 = QtGui.QCalendarWidget(Dialog)
        self.calendarWidget_2.setGeometry(QtCore.QRect(190, 220, 280, 155))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("Script MT Bold"))
        font.setBold(True)
        font.setWeight(75)
        self.calendarWidget_2.setFont(font)
        self.calendarWidget_2.setSelectedDate(QtCore.QDate(2019, 3, 27))
        self.calendarWidget_2.setObjectName(_fromUtf8("calendarWidget_2"))
        self.label = QtGui.QLabel(Dialog)
        self.label.setGeometry(QtCore.QRect(10, 220, 101, 20))
        self.label.setObjectName(_fromUtf8("label"))
        self.dateEdit = QtGui.QDateEdit(Dialog)
        self.dateEdit.setGeometry(QtCore.QRect(280, 380, 91, 21))
        self.dateEdit.setDateTime(QtCore.QDateTime(QtCore.QDate(2019, 3, 27), QtCore.QTime(0, 0, 0)))
        self.dateEdit.setDate(QtCore.QDate(2019, 3, 27))
        self.dateEdit.setObjectName(_fromUtf8("dateEdit"))
        self.dateEdit_2 = QtGui.QDateEdit(Dialog)
        self.dateEdit_2.setGeometry(QtCore.QRect(280, 170, 91, 21))
        self.dateEdit_2.setDate(QtCore.QDate(2019, 2, 22))
        self.dateEdit_2.setObjectName(_fromUtf8("dateEdit_2"))
        self.label_2 = QtGui.QLabel(Dialog)
        self.label_2.setGeometry(QtCore.QRect(10, 20, 71, 20))
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.label_3 = QtGui.QLabel(Dialog)
        self.label_3.setGeometry(QtCore.QRect(530, 510, 141, 16))
        self.label_3.setObjectName(_fromUtf8("label_3"))
        self.label_4 = QtGui.QLabel(Dialog)
        self.label_4.setGeometry(QtCore.QRect(530, 530, 111, 16))
        self.label_4.setObjectName(_fromUtf8("label_4"))
        self.pushButton = QtGui.QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(280, 430, 91, 23))
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        self.label_5 = QtGui.QLabel(Dialog)
        self.label_5.setGeometry(QtCore.QRect(10, 380, 181, 16))
        self.label_5.setObjectName(_fromUtf8("label_5"))
        self.label_6 = QtGui.QLabel(Dialog)
        self.label_6.setGeometry(QtCore.QRect(10, 460, 81, 16))
        self.label_6.setObjectName(_fromUtf8("label_6"))
        self.lineEdit = QtGui.QLineEdit(Dialog)
        self.lineEdit.setGeometry(QtCore.QRect(280, 460, 91, 20))
        self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
        self.label_7 = QtGui.QLabel(Dialog)
        self.label_7.setGeometry(QtCore.QRect(10, 170, 91, 16))
        self.label_7.setObjectName(_fromUtf8("label_7"))
        self.label_8 = QtGui.QLabel(Dialog)
        self.label_8.setGeometry(QtCore.QRect(110, 170, 51, 16))
        self.label_8.setObjectName(_fromUtf8("label_8"))
        self.label_9 = QtGui.QLabel(Dialog)
        self.label_9.setGeometry(QtCore.QRect(190, 380, 46, 13))
        self.label_9.setObjectName(_fromUtf8("label_9"))

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

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(_translate("Dialog", "Dialog", None))
        self.label.setText(_translate("Dialog", "Birthday Calendar", None))
        self.dateEdit.setDisplayFormat(_translate("Dialog", "d/m/yyyy", None))
        self.dateEdit_2.setDisplayFormat(_translate("Dialog", "d/m/yyyy", None))
        self.label_2.setText(_translate("Dialog", "2019 Calendar", None))
        self.label_3.setText(_translate("Dialog", "Marelize Jansen van Vuuren", None))
        self.label_4.setText(_translate("Dialog", "Student no: 60858753", None))
        self.pushButton.setText(_translate("Dialog", "Calculate Age", None))
        self.label_5.setText(_translate("Dialog", "Select DOB and Calculate exact age", None))
        self.label_6.setText(_translate("Dialog", "Current Age", None))
        self.label_7.setText(_translate("Dialog", "Select today\'s date", None))
        self.label_8.setText(_translate("Dialog", "D/MM/YYY", None))
        self.label_9.setText(_translate("Dialog", "D/MM/YY", None))


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    Dialog = QtGui.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())    

这是调用和显示用户界面的代码

import sys
from dispcalendar 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.calendarWidget, QtCore.SIGNAL('selectionChanged()'), self.dispdate)
        QtCore.QObject.connect(self.ui.calendarWidget_2, QtCore.SIGNAL('selectionChanged()'), self.dispdate)
        self.dispdate()

    def dispdate(self):
        self.ui.dateEdit_2.setDate(self.ui.calendarWidget.selectedDate())
        self.ui.dateEdit.setDate(self.ui.calendarWidget_2.selectedDate())
        self.ui.dateEdit_2.display(text)
        self.ui.dateEdit.display(text)
        self.ui.calendarWidget.display(text)
        self.ui.calendarWidget_2.display(text)

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

0 个答案:

没有答案