当前位置:网站首页>(6) Pyqt5--- > window jump (registration login function)
(6) Pyqt5--- > window jump (registration login function)
2022-06-25 12:36:00 【haoming Hu】
GitHub Connect :
This column all source code GitHub Through train
This column all source code Gitte Address
Another way to connect signals and slots was mentioned in the previous article
This blog was originally 2020 It should be released by the end of the year , Until now ! In the spare time of review , It's really enjoyable to be able to write something comfortable
This time, the main content is the interface jump to realize the login function
My method is clumsy , But it works . In fact, as long as one thing is completed, it will be completely OK 了 : When your login button is click When time is triggered , The slot function you connect to should be your own login API, Of course, this time I use the login interface function of my own server , When you use it, change it to your own login API Can , Come back , If you're successful , You need to send messages to each of the two interfaces , Make the action of closing this window and opening a new one , I'm used to writing slot functions in my own class , In this way, you can't pass information to another window object ( I haven't thought of a good way for the time being ), So I write this slot function directly in the main thread , Then the button binding event is also bound after the slot function .
I used to write tkinter That's what I did when I was young , There's nothing wrong at the moment , It can be said to be simple and rude
This code file mainly has
- login_ui.py
- main_ui.py
- main.py
The first two are ui Turning around py file ,main.py A file is a file in which a program runs
If you don't want to go GitHub If you download the code above , I just posted it
login_ui.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'login.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# 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
class Ui_login(object):
def setupUi(self, login):
login.setObjectName("login")
#login.setStyleSheet("#login{background-color:green}")
login.resize(412, 269)
self.id_label = QtWidgets.QLabel(login)
self.id_label.setGeometry(QtCore.QRect(110, 60, 51, 41))
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setPointSize(14)
self.id_label.setFont(font)
self.id_label.setObjectName("id_label")
self.pw_label_2 = QtWidgets.QLabel(login)
self.pw_label_2.setGeometry(QtCore.QRect(110, 120, 51, 41))
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setPointSize(14)
self.pw_label_2.setFont(font)
self.pw_label_2.setObjectName("pw_label_2")
self.login_pushButton = QtWidgets.QPushButton(login)
self.login_pushButton.setGeometry(QtCore.QRect(100, 200, 75, 23))
self.login_pushButton.setObjectName("login_pushButton")
self.exit_pushButton = QtWidgets.QPushButton(login)
self.exit_pushButton.setGeometry(QtCore.QRect(240, 200, 75, 23))
self.exit_pushButton.setObjectName("exit_pushButton")
self.lineEdit_id = QtWidgets.QLineEdit(login)
self.lineEdit_id.setGeometry(QtCore.QRect(170, 70, 113, 20))
self.lineEdit_id.setObjectName("lineEdit_id")
self.lineEdit_pw = QtWidgets.QLineEdit(login)
self.lineEdit_pw.setGeometry(QtCore.QRect(170, 130, 113, 20))
self.lineEdit_pw.setObjectName("lineEdit_pw")
self.lineEdit_pw.setEchoMode(QtWidgets.QLineEdit.Password)
self.retranslateUi(login)
self.exit_pushButton.clicked.connect(login.close)
QtCore.QMetaObject.connectSlotsByName(login)
def retranslateUi(self, login):
_translate = QtCore.QCoreApplication.translate
login.setWindowTitle(_translate("login", "Form"))
self.id_label.setText(_translate("login", " account number "))
self.pw_label_2.setText(_translate("login", " password "))
self.login_pushButton.setText(_translate("login", " Sign in "))
self.exit_pushButton.setText(_translate("login", " sign out "))
main_ui.py file
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'main.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# 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
class Ui_main(object):
def setupUi(self, main):
main.setObjectName("main")
main.resize(1007, 631)
self.retranslateUi(main)
QtCore.QMetaObject.connectSlotsByName(main)
def retranslateUi(self, main):
_translate = QtCore.QCoreApplication.translate
main.setWindowTitle(_translate("main", "Form"))
main.py file
""" /******************************************************************************** * @Filename: main.py * @Author: haomingHu * @Version: 1.0 * @Date: 2021-03-26 * @Description: * @History: ********************************************************************************/ """
from login_ui import Ui_login
from main_ui import Ui_main
import sys
from PyQt5 import QtWidgets
from PyQt5.QtGui import QPalette,QBrush,QPixmap
from PyQt5.QtCore import Qt
class myLogin(QtWidgets.QWidget,Ui_login):
login_state = 0
def __init__(self):
super(myLogin,self).__init__()
self.setupUi(self)
loginPalette = QPalette()
loginPalette.setBrush(QPalette.Background, QBrush(QPixmap("./loginbackground.jpg")))
#loginPalette.setColor(QPalette.Background, Qt.blue)
self.setPalette(loginPalette)
class myMainGui(QtWidgets.QWidget,Ui_main):
userID = ""
# Constructors
def __init__(self):
super(myMainGui,self).__init__()
self.setupUi(self)
def closeEvent(self,event):# The function name is fixed and immutable
reply=QtWidgets.QMessageBox.question(self,u'Notice!',u'Are you sure to exit?'
,QtWidgets.QMessageBox.Yes,QtWidgets.QMessageBox.No)
#QtWidgets.QMessageBox.question(self,u' Pop up window name ',u' Pop-up content ', Options 1, Options 2)
if reply==QtWidgets.QMessageBox.Yes:
event.accept()# close window
else:
event.ignore()# Ignore the click X event
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
myLogin = myLogin()
myLogin.show()
mainGUI = myMainGui()
userIDSure = ""
flag = 0
def login_check():
userID = myLogin.lineEdit_id.text()
user_PW = myLogin.lineEdit_pw.text()
print(userID)
print(user_PW)
''' Here I use the login request interface of my server When you use it, you can replace it with your own encapsulated login verification interface '''
''' Normally , If you log in successfully , You need to send the successful login user information back to the main interface That is to tell the main interface , Which user logged in , At this time, it can be defined in the class of the main interface Some class properties , If login is successful , Will lineedit The input content of the object can be assigned to the class property '''
#login_flag = event.loginRequest(userID,user_PW)
#if login_flag == 0:
if userID == "1" and user_PW == "1":
myLogin.login_state = 1
mainGUI.userID = myLogin.lineEdit_id.text()
myLogin.close()
mainGUI.show()
myLogin.login_pushButton.clicked.connect(login_check)
sys.exit(app.exec_())

Supplementary information :
- obtain lineedit How to input content :
Use lineedit Of text Method to get , The object obtained is a string object .
userID = myLogin.lineEdit_id.text()
user_PW = myLogin.lineEdit_pw.text()
- Set the background ( I'll write a blog later )
- Window objects come with setStyleSheet Method
login.setObjectName("login")
login.setStyleSheet("#login{background-color:green}")
2、 Use QPalette class
window = QMainWindow()
palette = QPalette()
palette.setColor(QPalette.Background, Qt.red)
window.setPalette(palette)
I wish you all a happy life , Happy learning !
边栏推荐
- 揭秘GaussDB(for Redis):全面對比Codis
- 刷入Magisk通用方法
- Qiantang Pingou source code -- Qiantang Pingou app system development source code sharing
- ThinkPHP upload image compression size
- The first techo day Tencent technology open day in 2022 will be held online on June 28
- thinkphp3.2.5 GIF. class. php for php7.4
- Go novice exploration road 2
- 19. Implementation of MVVM architecture based on WPF event to command
- 一篇文章讲清楚MySQL的聚簇/联合/覆盖索引、回表、索引下推
- ECSHOP upload video_ ECSHOP video list, video classification, video related product guide
猜你喜欢

An easy-to-use seal design tool - (can be converted to ofd file)

Explanation of ideas and sharing of pre-processing procedures for 2021 US game D (with pre-processing data code)

Zhangxiaobai's road of penetration (VI) -- the idea and process of SQL injection and the concat series functions and information of SQL_ Schema database explanation

Understanding and construction of devsecops and Devops
![[oceanbase] Introduction to oceanbase and its comparison with MySQL](/img/1c/bd2bcddb7af4647407d2bc351f5f5d.png)
[oceanbase] Introduction to oceanbase and its comparison with MySQL

Laravel excel export

Go novice exploration road 1

How to use ARIMA model for prediction?

Installation and removal of MySQL under Windows

ECSHOP quickly purchases goods, simplifies the shopping process, and improves the user experience through one-step shopping
随机推荐
15. Notes on the button style of WPF
Image tagging to obtain the coordinates of the image in the ImageView
PHP parsing QR code content
Repair the error that ECSHOP background orders prompt insufficient inventory when adding goods. Please reselect
What is principal component analysis? Dimension reduction of classical case analysis variables
R language uses ordinal or. The display function obtains the summary statistical information of the ordered logistic regression model (the odds ratio and its confidence interval corresponding to the v
Zhangxiaobai's way of penetration (V) -- detailed explanation of upload vulnerability and parsing vulnerability
Arm V7 LDR STR memory access
Zhangxiaobai's road of penetration (VI) -- the idea and process of SQL injection and the concat series functions and information of SQL_ Schema database explanation
20. MVVM command binding of WPF
一篇文章讲清楚MySQL的聚簇/联合/覆盖索引、回表、索引下推
[on]learning dynamic and hierarchical traffic spatiotemporal features with transformer
2022 meisai topic C idea sharing + translation
What is Flink? What can Flink do?
Possible causes of wechat applet decryption failure
Network | indicators and test methods to measure the quality of the network
The source code of the hottest online disk money making system in 2022 imitates Lanzou online disk / Chengtong online disk / sharing money making cloud disk system / online disk VIP Download System
Mpai data science platform random forest classification \ explanation of regression parameter adjustment
Array reorder based on a field
Mind mapping video