pyqt5 设计简单登陆界面,含记住密码功能

from PyQt5 import *
import configparser
from untitled import Ui_MainWindow
from PyQt5 import QtWidgets
from PyQt5 import QtCore
import sys

class UI(object):
    def __init__(self):
        QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
        self.app = QtWidgets.QApplication(sys.argv)  # 生成应用
        self.window = QtWidgets.QMainWindow()  # 生成窗口q
        self.ui = Ui_MainWindow()  # 使用QTdesigner自动创建的类
        self.ui.setupUi(self.window)
        self.win_adjust()
        self.window.show()
        self.others()
        sys.exit(self.app.exec_())

    def others(self):
        self.ui.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.Password)
        self.component_connect()
        self.load_config()

    def win_adjust(self):
        import win32api, win32con
        # self.window.resize(win32api.GetSystemMetrics(win32con.SM_CXSCREEN) / 2,
        #                    win32api.GetSystemMetrics(win32con.SM_CYSCREEN) / 2)

    def component_connect(self):
        self.ui.pushButton.clicked.connect(self.login)

    def load_config(self):
        config = configparser.ConfigParser()
        file = config.read(‘user.ini‘)
        config_dict = config.defaults()
        self.user_name = config_dict[‘user_name‘]
        self.ui.lineEdit.setText(self.user_name)
        if config_dict[‘remember‘] == ‘True‘:
            self.password = config_dict[‘password‘]
            self.ui.lineEdit_2.setText(self.password)
            self.ui.checkBox.setChecked(True)
        else:
            self.ui.checkBox.setChecked(False)

    def login(self):
        self.user_name = self.ui.lineEdit.text()
        self.password = self.ui.lineEdit_2.text()
        config = configparser.ConfigParser()
        if self.ui.checkBox.isChecked():
            config["DEFAULT"] = {
                "user_name": self.user_name,
                "password": self.password,
                "remember": self.ui.checkBox.isChecked()
            }
        else:
            config["DEFAULT"] = {
                "user_name": self.user_name,
                "password": "",
                "remember": self.ui.checkBox.isChecked()
            }
        with open(‘user.ini‘, ‘w‘)as configfile:
            config.write((configfile))

        print(self.user_name, self.password)

if __name__ == ‘__main__‘:
    # import reInterpreter as inter
    ui = UI()

#以下为QT设计师生成的界面代码:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file ‘untitled.ui‘
#
# Created by: PyQt5 UI code generator 5.11.3
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(315, 226)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName("gridLayout")
        self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_4.addItem(spacerItem)
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setObjectName("pushButton")
        self.horizontalLayout_4.addWidget(self.pushButton)
        spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_4.addItem(spacerItem1)
        self.gridLayout.addLayout(self.horizontalLayout_4, 5, 0, 1, 1)
        spacerItem2 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.gridLayout.addItem(spacerItem2, 0, 0, 1, 1)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        spacerItem3 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem3)
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setObjectName("label_2")
        self.horizontalLayout.addWidget(self.label_2)
        self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.horizontalLayout.addWidget(self.lineEdit_2)
        spacerItem4 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem4)
        self.gridLayout.addLayout(self.horizontalLayout, 2, 0, 1, 1)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        spacerItem5 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_2.addItem(spacerItem5)
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setObjectName("label")
        self.horizontalLayout_2.addWidget(self.label)
        self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit.setObjectName("lineEdit")
        self.horizontalLayout_2.addWidget(self.lineEdit)
        spacerItem6 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_2.addItem(spacerItem6)
        self.gridLayout.addLayout(self.horizontalLayout_2, 1, 0, 1, 1)
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        spacerItem7 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_3.addItem(spacerItem7)
        self.checkBox = QtWidgets.QCheckBox(self.centralwidget)
        self.checkBox.setObjectName("checkBox")
        self.horizontalLayout_3.addWidget(self.checkBox)
        self.checkBox_2 = QtWidgets.QCheckBox(self.centralwidget)
        self.checkBox_2.setObjectName("checkBox_2")
        self.horizontalLayout_3.addWidget(self.checkBox_2)
        self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_2.setStyleSheet("background-color:rgba(0,0,0,0);")
        self.pushButton_2.setObjectName("pushButton_2")
        self.horizontalLayout_3.addWidget(self.pushButton_2)
        spacerItem8 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_3.addItem(spacerItem8)
        self.gridLayout.addLayout(self.horizontalLayout_3, 4, 0, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 315, 18))
        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", "                 登陆                "))
        self.label_2.setText(_translate("MainWindow", "密码        "))
        self.label.setText(_translate("MainWindow", "用户名      "))
        self.checkBox.setText(_translate("MainWindow", "记住密码"))
        self.checkBox_2.setText(_translate("MainWindow", "自动登陆"))
        self.pushButton_2.setText(_translate("MainWindow", "    找回密码"))

原文地址:https://www.cnblogs.com/pqhuang/p/11404402.html

时间: 2024-10-29 10:46:55

pyqt5 设计简单登陆界面,含记住密码功能的相关文章

登陆界面的记住密码

//页面一出现则获取NSUserDefaults里面rememberSate的状态来改变UI -(void)viewWillAppear:(BOOL)animated{ NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; NSString *rememberSate = [userDefaults objectForKey:@"rememberSate"]; if ([rememberSate is

清空浏览器缓存,网站登陆界面仍然记住密码

这显然不是啥技术博文啦,只是记载下平时遇到的小问题~ 如题,在FireFox下清空下图选项,登陆淘宝的时候,还是会自动填写账号密码. 然后我就进入工具-选项 看了下,结果在安全里找到了,所有已保存的密码都在这了...

js中利用cookie实现记住密码功能

js中利用cookie实现记住密码功能 在登录界面添加记住密码功能,我首先想到的是在java后台中调用cookie存放账号密码,大致如下: 1 HttpServletRequest request 2 HttpServletResponse response 3 Cookie username = new Cookie("username ","cookievalue"); 4 Cookie password = new Cookie("password

easyui简单登陆界面

原文:easyui简单登陆界面 源代码下载地址:http://www.zuidaima.com/share/1550463738088448.htm easyui一个简单的登录页面

winform设计一个登录界面和修改密码的界面-自动切换窗体(问题[已解] 望一起讨论)(技术改变世界-cnblog)

http://www.cnblogs.com/IAmBetter/archive/2012/01/14/2322156.html winform设计一个登录界面和修改密码的界面-自动切换窗体(问题[已解] 望一起讨论)(技术改变世界-cnblog) 需求 登录界面: 1.要求 密码 文本可以显示和隐藏 字符 password属性 2.显示输入按钮button 要求显示输入按钮 按下去之后,实现 名字变成“取消”,取消之后密码又是隐藏的 3.要求只能输入错误 3次,3次之后自动退出 4.要求点击修

Android Minitwitter 记住密码功能

MiniTwitter记住密码功能实现      首先,在进入本次主要内容之前说一下,本功能的实现是在twitter登陆界面的基础上操作,但本次主要任务内容是记住密码的功能实现,所以登陆界面不在详细介绍. 如图:为本次实验的结果图: 1.界面介绍 布局构造:布局分为三大部分 (1)背景:使用LinearLayout布局: (2)浅蓝色部分:使用RelativeLayout布局: 注意:这里用到圆角设置corners和填充色设置solid: (3)输入框和按钮:使用TextView.EditTex

android: SharedPreferences实现记住密码功能

既然是实现记住密码的功能,那么我们就不需要从头去写了,因为在上一章中的最佳实 践部分已经编写过一个登录界面了,有可以重用的代码为什么不用呢?那就首先打开 BroadcastBestPractice 项目,来编辑一下登录界面的布局.修改 login.xml 中的代码,如下 所示: <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="mat

ssh 解决经常断开与记住密码功能

一.解决ssh经常自动断开问题 修改 /etc/ssh/ssh_config 其中对应项为 ClientAliveInterval 30 ClientAliveCountMax 3 表示每30秒发一次心跳测试请求,如果失败3次则断开连接(数值可酌情修改) 二.ssh记住密码功能 1. 生成一个新的sshkey(如果没有的话,已存在则可直接执行第二步) 可以使用如下命令 ssh-keygen -t rsa -b 4096 -C "[email protected]" 或简单的直接输入 s

Android &#39;记住密码&#39;功能

1.运行后界面图 2.主要代码: 2.1 activity_main.xml(2个TextView 2个EditText 1个CheckBox以及1个Button): 1 <TextView 2 android:id="@+id/tvAccount" 3 android:layout_width="wrap_content" 4 android:layout_height="wrap_content" 5 android:layout_al