我正在使用以登录窗口开头的Python Qt应用程序。登录后,我要显示正常的应用程序窗口。作为测试,我尝试两次显示AuthWindow(登录窗口)。预期的效果是,先打开一次登录窗口,然后关闭它,然后打开第二个窗口,依此类推。第一个打开,关闭它并退出程序实际上发生了什么。
import sys
from PyQt4 import QtGui
from AuthWindow import AuthWindow
def main():
app = QtGui.QApplication(sys.argv)
w = AuthWindow()
w.show()
w = AuthWindow()
w.show()
sys.exit(app.exec())
if __name__ == '__main__':
main()
这是AuthWindow的代码:
from PyQt4 import QtGui
class AuthWindow(QtGui.QDialog):
User, Admin = range(2)
def __init__(self, parent = None):
super().__init__(parent)
self.setWindowTitle('Login')
hbox = QtGui.QHBoxLayout(self)
vbox = QtGui.QVBoxLayout()
self.username = QtGui.QLineEdit()
self.password = QtGui.QLineEdit()
vbox.addWidget(QtGui.QLabel('Username'))
vbox.addWidget(self.username)
vbox.addWidget(QtGui.QLabel('Password'))
vbox.addWidget(self.password)
btn = QtGui.QPushButton('Login')
btn.clicked.connect(self.loginClicked)
hbox.addLayout(vbox)
hbox.addWidget(btn)
self.password.setEchoMode(QtGui.QLineEdit.Password)
def loginClicked(self, ev):
auth = self.checkLogin()
print(auth)
def checkLogin(self):
username = self.username.text()
password = self.password.text()
print(username)
print(password)
# login logic will go here...
忽然笑
相关分类