免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3774 | 回复: 1
打印 上一主题 下一主题

pyqt中的self.accept()不管用 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-12-10 10:54 |只看该作者 |倒序浏览
代码如下:
from PyQt4 import QtGui, QtCore
try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s
class Ui_Dialog( QtGui.QDialog):
    def setupUi(self, Dialog):
        Dialog.setObjectName(_fromUtf8("Dialog")
        Dialog.resize(670, 596)
        Dialog.setInputMethodHints(QtCore.Qt.ImhNone)
        Dialog.setModal(False)
        self.pushButton = QtGui.QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(100, 310, 101, 31))
        self.pushButton.setObjectName(_fromUtf8("pushButton")
        self.pushButton_2 = QtGui.QPushButton(Dialog)
        self.pushButton_2.setGeometry(QtCore.QRect(320, 310, 91, 31))
        self.pushButton_2.setObjectName(_fromUtf8("pushButton_2")
        self.label = QtGui.QLabel(Dialog)
        self.label.setGeometry(QtCore.QRect(80, 60, 111, 41))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("黑体")
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.label.setFont(font)
        self.label.setObjectName(_fromUtf8("label")
        self.label_2 = QtGui.QLabel(Dialog)
        self.label_2.setGeometry(QtCore.QRect(80, 140, 111, 31))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("黑体")
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.label_2.setFont(font)
        self.label_2.setObjectName(_fromUtf8("label_2")
        self.lineEdit = QtGui.QLineEdit(Dialog)
        self.lineEdit.setGeometry(QtCore.QRect(200, 70, 191, 31))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("黑体")
        font.setPointSize(16)
        font.setBold(True)
        font.setWeight(75)
        self.lineEdit.setFont(font)
        self.lineEdit.setEchoMode(QtGui.QLineEdit.Normal)
        self.lineEdit.setObjectName(_fromUtf8("lineEdit")
        self.lineEdit_2 = QtGui.QLineEdit(Dialog)
        self.lineEdit_2.setGeometry(QtCore.QRect(200, 140, 191, 31))
        font = QtGui.QFont()
        font.setFamily(_fromUtf8("黑体")
        font.setPointSize(16)
        font.setBold(True)
        font.setWeight(75)
        self.lineEdit_2.setFont(font)
        self.lineEdit_2.setEchoMode(QtGui.QLineEdit.Password)
        self.lineEdit_2.setObjectName(_fromUtf8("lineEdit_2"))

        self.retranslateUi(Dialog)
        QtCore.QObject.connect(self.pushButton_2, QtCore.SIGNAL(_fromUtf8("clicked()")), Dialog.close)
        QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.login)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF)
        self.pushButton.setText(QtGui.QApplication.translate("Dialog", "确定", None, QtGui.QApplication.UnicodeUTF)
        self.pushButton_2.setText(QtGui.QApplication.translate("Dialog", "取消", None, QtGui.QApplication.UnicodeUTF)
        self.label.setText(QtGui.QApplication.translate("Dialog", "用户名:", None, QtGui.QApplication.UnicodeUTF)
        self.label_2.setText(QtGui.QApplication.translate("Dialog", "密  码:", None, QtGui.QApplication.UnicodeUTF)
   
        
    def login(self):
        if self.lineEdit.text()== u'admin' and  self.lineEdit_2.text()== u'admin':
            # 如果用户名和密码正确,关闭对话框,accept()关闭后,如果增加一个取消按钮调用reject()
            
            self.accept()

        else:
            QtGui.QMessageBox.critical(self, 'Error', 'User name or password error')
   
class myyy(QtGui.QDialog):   
    def __init__(self, parent=None):
        QtGui.QDialog.__init__(self, parent)
        self.ui=Ui_Dialog()
        self.ui.setupUi(self)
   

if __name__ == '__main__':
    import sys
    app = QtGui.QApplication(sys.argv)
    log=myyy()
    if log.exec_()==QtGui.QDialog.Accepted:
        win = QtGui.QMainWindow()
        win.show()
        sys.exit(app.exec_())
点击“确定”不能关闭,小弟初学,请大家帮忙!

论坛徽章:
0
2 [报告]
发表于 2012-12-10 17:08 |只看该作者
已经搞定了,是自己弄错了!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP