登录界面进入功能界面后会闪退(窗口开启一次后关闭)实际上是无法循环窗口
class mainwindow(QMainWindow, Ui_Form):
def __init__(self):
super(mainwindow, self).__init__()
self.setupUi(self)
self.butlogin.clicked.connect(self.login)
def login(self):
# 获取用户输入的用户名和密码
username = self.editlogin.text()
password = self.editpassword.text()
self.close()
# 判断用户名和密码是否正确,这里假设用户名为admin,密码为123456
if username == "a" and password == "1":
# 弹出对话框提示用户登录成功
QtWidgets.QMessageBox.information(QtWidgets.QWidget(), "提示", "登录成功!", QtWidgets.QMessageBox.Ok)
new = mainwindow1()
new.show()
else:
# 弹出对话框提示用户登录失败
QtWidgets.QMessageBox.warning(QtWidgets.QWidget(), "警告", "用户名或密码错误!", QtWidgets.QMessageBox.Ok)
我们给窗口加上self,即可运行
self.new = mainwindow1()
self.new.show()
通过自定义class,调用自身,显示窗口
class mainwindow1(QMainWindow, Ui_dialog):
def __init__(self):
super(mainwindow1, self).__init__()
self.setupUi(self)
class mainwindow(QMainWindow, Ui_Form):
def __init__(self):
super(mainwindow, self).__init__()
self.setupUi(self)
#接下来这两个窗口就可以调用了 eg: ui = mainwindow() ui.show()
#可以在主进程调用,也可以互相调用,要把未放入主进程的界面放入主进程中 eg: self.xxx(见上一条)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
Ui = mainwindow()
Ui.show()
sys.exit(app.exec_())