- 论坛徽章:
- 0
|
代码如下:
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_())
点击“确定”不能关闭,小弟初学,请大家帮忙! |
|