【Pyqt5】实现登录界面、主界面的相互跳转

简介: 【Pyqt5】实现登录界面、主界面的相互跳转

演示


pyqt5实现登录界面、主界面相互跳转


功能


1、登录:登陆后跳转主界面

2、登出:登出后跳转登录界面


编程思路


1、使用designer设计界面生成ui文件。命令行执行pyuic5 -o xxx.py xxx.ui实现.ui转.py。designer位于qt5_applications\Qt\bin

1684136018661.jpg

2、设计模块代码架构。使模块具备更强的可读性,可编写性、拓展性

3、新类继承py文件中的ui类,编写相关槽函数或其他功能性实例函数


运行教程+源代码


pip install pyqt5
pip install pyqt5-tools

main.py

from login import Ui_Dialog
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from index import MainUI
class Main(Ui_Dialog):
    def __init__(self):
        super(Main, self).__init__()
        self.window = QMainWindow()
        self.setupUi(self.window)
        self.pushButton.clicked.connect(self.logining)
        self.window.show()
    def logining(self):
        self.main_ui = MainUI(self)
        self.main_ui.pushButton.clicked.connect(self.loginout)
        self.window.close()
        self.main_ui.mainwindow.show()
    def loginout(self):
        self.main_ui.mainwindow.close()
        self.window.show()
if __name__ == '__main__':
    app = QApplication([])
    stats = Main()
    app.exec_()


login.py

# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '11.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
import os
import qt5_applications
dirname = os.path.dirname(qt5_applications.__file__)
plugin_path = os.path.join(dirname, 'Qt', 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(400, 277)
        self.pushButton = QtWidgets.QPushButton(Dialog)
        self.pushButton.setGeometry(QtCore.QRect(120, 170, 75, 23))
        self.pushButton.setStyleSheet("")
        self.pushButton.setObjectName("pushButton")
        self.pushButton_2 = QtWidgets.QPushButton(Dialog)
        self.pushButton_2.setGeometry(QtCore.QRect(210, 170, 75, 23))
        self.pushButton_2.setObjectName("pushButton_2")
        self.lineEdit = QtWidgets.QLineEdit(Dialog)
        self.lineEdit.setGeometry(QtCore.QRect(120, 60, 161, 21))
        self.lineEdit.setStyleSheet("")
        self.lineEdit.setObjectName("lineEdit")
        self.lineEdit_2 = QtWidgets.QLineEdit(Dialog)
        self.lineEdit_2.setGeometry(QtCore.QRect(120, 110, 161, 21))
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)
    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
        self.pushButton.setText(_translate("Dialog", "PushButton"))
        self.pushButton_2.setText(_translate("Dialog", "PushButton"))


index.py

# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'index.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(700, 20, 75, 23))
        self.pushButton.setObjectName("pushButton")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 23))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.pushButton.setText(_translate("MainWindow", "PushButton"))
class MainUI(Ui_MainWindow):
    def __init__(self,window):
        super(MainUI, self).__init__()
        self.mainwindow=QMainWindow()
        self.setupUi(self.mainwindow)

云盘链接:https://pan.baidu.com/s/18BwnxE3NtBxJuPk_90vikA

提取码:s6ai

相关文章
Fastadmin后台页面添加顶部按钮
操作的前提是需要在fastadmin框架中添加对应的控制器、模型、视图页面,可以手动创建,也可以使用curd一键生成。
237 0
|
小程序 开发者
小程序中点击按钮跳转另外一个小程序
小程序中点击按钮跳转另外一个小程序
315 0
|
C++ Python
Python密码锁屏窗体界面
Python密码锁屏窗体界面
126 0
Python密码锁屏窗体界面
|
数据安全/隐私保护
今天将用户注册,登陆的三个界面界面及其倒计时。 注册和登录分别有三个界面,原理都类似。如下:
今天将用户注册,登陆的三个界面界面及其倒计时。 注册和登录分别有三个界面,原理都类似。如下:
114 0
|
缓存 API PHP
接口测试|Fiddler界面主菜单功能介绍(二)
接口测试|Fiddler界面主菜单功能介绍(二)
136 0
接口测试|Fiddler界面主菜单功能介绍(二)
|
存储 缓存
接口测试|Fiddler界面主菜单功能介绍(一)
接口测试|Fiddler界面主菜单功能介绍(一)
110 0
接口测试|Fiddler界面主菜单功能介绍(一)
|
关系型数据库 MySQL 数据库
Qt实现登陆界面(含代码)
Qt实现登陆界面(含代码)
570 0
Qt实现登陆界面(含代码)
|
小程序
小程序-点击按钮式 进行页面之间的跳转
小程序-点击按钮式 进行页面之间的跳转
Qt-网易云音乐界面实现-8 主导航的实现-QtabWidget
哎呀,堕落了,快有小两周没哟更新了,是在是没有动力了,浏览量连三位数都没有,是在是没有写下去的信心。
150 0
Qt-网易云音乐界面实现-8 主导航的实现-QtabWidget