用pyqt5 编写一个可实现账号密码登录的界面,点击登录可跳转主界面的程序代码。刚学,弄了好几天都没头绪,求大神帮帮忙。
参考这个:https://www.cnblogs.com/ansang/p/7895075.html
至于你要完整的功能,还需要数据库,这个你就要系统学习了。
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
from PyQt4 import QtGui, QtCore
QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8"))
NUM=0
class main():
def init(self,parent=None):
super(main,self).__init__(parent)
self.num=10
print self.num
def setnum(self,s):
self.num=s
class MessageBoxDlg(QDialog):
def init(self,parent=None):
super(MessageBoxDlg,self).__init__(parent)
self.setWindowTitle("Login")
self.label=QLabel("Please input your accout and passwd:")
# self.gridLayout0
#self.hboxlayout1
self.textField1= QtGui.QLineEdit()
self.showButton = QLabel( u"Password:" )
self.hboxlayout1 = QtGui.QHBoxLayout()
self.hboxlayout1.addWidget( self.showButton )
self.hboxlayout1.addWidget( self.textField1 )
#self.hboxlayout1.addStretch(1)
#self.hboxlayout4
self.textField4= QtGui.QLineEdit()
self.showButton4 = QLabel( u"User: " )
self.hboxlayout4 = QtGui.QHBoxLayout()
self.hboxlayout4.addWidget( self.showButton4 )
self.hboxlayout4.addWidget( self.textField4 )
#self.hboxlayout1.addStretch(1)
# self.hboxlayout2
questionButton=QPushButton("OK")
informationButton=QPushButton("Cancel")
self.hboxlayout2 = QtGui.QHBoxLayout()
self.hboxlayout2.addWidget( questionButton )
self.hboxlayout2.addWidget( informationButton )
#self.hboxlayout2.addStretch(1)
self.vboxlayout3 = QtGui.QVBoxLayout()
self.vboxlayout3.setMargin(10)
self.vboxlayout3.setSpacing(6)
self.vboxlayout3.addWidget( self.label )
self.vboxlayout3.addLayout( self.hboxlayout4 )
self.vboxlayout3.addLayout( self.hboxlayout1 )
self.vboxlayout3.addLayout( self.hboxlayout2 )
self.setLayout( self.vboxlayout3 )
self.connect(questionButton,SIGNAL("clicked()"),self.slotQuestion)
self.connect(informationButton,SIGNAL("clicked()"),self.slotInformation)
def slotQuestion(self):
global NUM
NUM=5
print NUM
pass
def slotInformation(self):
sys.exit()
app=QApplication(sys.argv)
MessageBox=MessageBoxDlg()
MessageBox.show()
app.exec_()