首页 > 其他分享 >4.12今日总结

4.12今日总结

时间:2023-04-12 20:46:03浏览次数:41  
标签:总结 username 4.12 layout edit self addWidget 今日 password

今天学习了Qt的登录注册页面的跳转

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout, QMessageBox


class Login(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Login")
        self.setFixedSize(400, 300)

        # 用户名输入框
        self.username_label = QLabel("Username:")
        self.username_edit = QLineEdit()
        self.username_layout = QHBoxLayout()
        self.username_layout.addWidget(self.username_label)
        self.username_layout.addWidget(self.username_edit)

        # 密码输入框
        self.password_label = QLabel("Password:")
        self.password_edit = QLineEdit()
        self.password_edit.setEchoMode(QLineEdit.Password)
        self.password_layout = QHBoxLayout()
        self.password_layout.addWidget(self.password_label)
        self.password_layout.addWidget(self.password_edit)

        # 登录按钮
        self.login_button = QPushButton("Login")
        self.login_button.clicked.connect(self.login)

        # 注册按钮
        self.signup_button = QPushButton("Sign up")
        self.signup_button.clicked.connect(self.show_signup)

        # 页面布局
        self.layout = QVBoxLayout()
        self.layout.addLayout(self.username_layout)
        self.layout.addLayout(self.password_layout)
        self.layout.addWidget(self.login_button)
        self.layout.addWidget(self.signup_button)
        self.setLayout(self.layout)

    def login(self):
        # 在此处写登录逻辑
        username = self.username_edit.text()
        password = self.password_edit.text()

        if username == "admin" and password == "password":
            QMessageBox.information(self, "Login Successful", "Welcome, Admin!")
        else:
            QMessageBox.warning(self, "Login Failed", "Incorrect username or password. Please try again.")

    def show_signup(self):
        self.signup_window = Signup()
        self.signup_window.show()
        self.hide()


class Signup(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Sign up")
        self.setFixedSize(400, 300)

        # 用户名输入框
        self.username_label = QLabel("Username:")
        self.username_edit = QLineEdit()
        self.username_layout = QHBoxLayout()
        self.username_layout.addWidget(self.username_label)
        self.username_layout.addWidget(self.username_edit)

        # 密码输入框
        self.password_label = QLabel("Password:")
        self.password_edit = QLineEdit()
        self.password_edit.setEchoMode(QLineEdit.Password)
        self.password_layout = QHBoxLayout()
        self.password_layout.addWidget(self.password_label)
        self.password_layout.addWidget(self.password_edit)

        # 确认密码输入框
        self.confirm_label = QLabel("Confirm Password:")
        self.confirm_edit = QLineEdit()
        self.confirm_edit.setEchoMode(QLineEdit.Password)
        self.confirm_layout = QHBoxLayout()
        self.confirm_layout.addWidget(self.confirm_label)
        self.confirm_layout.addWidget(self.confirm_edit)

        # 注册按钮
        self.signup_button = QPushButton("Sign up")
        self.signup_button.clicked.connect(self.signup)

        # 返回按钮
        self.back_button = QPushButton("Back to Login")
        self.back_button.clicked.connect(self.show_login)

        # 页面布局
        self.layout = QVBoxLayout()
        self.layout.addLayout(self.username_layout)
        self.layout.addLayout(self.password_layout)
        self.layout.addLayout(self.confirm_layout)
        self.layout.addWidget(self.signup_button)
        self.layout.addWidget(self.back_button)
        self.setLayout(self.layout)

    def signup(self):
        # 在此处写注册逻辑
        username = self.username_edit.text()
        password = self.password_edit.text()
        confirm_password = self.confirm_edit.text()

        if password != confirm_password:
            QMessageBox.warning(self, "Signup Failed", "Password does not match. Please check again.")
        else:
            QMessageBox.information(self, "Signup Successful", f"Welcome, {username}!")
            self.show_login()

    def show_login(self):
        self.login_window = Login()
        self.login_window.show()
        self.hide()


if __name__ == "__main__":
    app = QApplication([])
    login_window = Login()
    login_window.show()
    app.exec_()

 

标签:总结,username,4.12,layout,edit,self,addWidget,今日,password
From: https://www.cnblogs.com/yangkaiwen/p/17311161.html

相关文章

  • 4.12趣味百题第六题
    一问题描述   用牛顿迭代法。牛顿迭代法x=x0-f(x0)/f'(x0),迭代到|x-x0|<=10^-5.方程ax*x*x+b*x*x+c*x+d=0;系数a,b,c,d由主函数输入.求x在1附近的一个根并输出。二设计思路1.设置一个在1附近的x0;2.利用do-while迭代法求x.三流程图四伪代码intx,x0=2inta,......
  • scrum项目冲刺_day1会议总结
    今日团队任务:图片转excel(5天)前端开发(需团队风格统一)调用接口(后端),json数据->excel前后端连接          任烁玚(进行中)            图片转html(8天)前端开发(需团队风格统一)图片转为pdf(存储)pdf转html(调用接口)[html存储到数据库]前后台数据同......
  • 2023年4.12软工日报
    今天下午实现了安卓从服务器中下载。  ......
  • 2023.4.12学习随笔:学贪心学到数组循环
    代码随想录(programmercarl.com)在做这个题时候发现数组循环%没看懂,就开始琢磨这一点,查了很多资料都没有讲,可能是这个知识比较基础(嘿嘿我基础太差了)慢慢来吧~ 编程的时候,很多时候都会要求一个数在某一个范围内进行反复循环,0~100循环,0~5循环等等。一般的方法是使用if语句,当判断......
  • 繁星队4.12团队项目计划会议
    下午两点召开了本团队项目计划会议,由队长进行了智能建立解析系统的页面,基本功能和数据库的展示,讨论了完整系统的功能,确定了团队计划backlog,制定了任务索引卡,进行了工作认领和时间估计。会议视频:https://www.bilibili.com/video/BV1oj411c7L4/?buvid=XUED062ED9D795F27DFBBCF5DA70......
  • 英语每日(4.12)
    commissondiscriminationarchitectchancellorpromptdiscardtuitionverbalsubscribeprescribeascribereluctantsolecomplycoordinateaccommodateobligecommoditygarmentconstarinconvictthesisunchartedcharteressenceanti......
  • mysql查询过程优化--理论及实践过程总结
    首先推荐一篇写的特别详细的帖子,感觉写的太好了。全看懂了,就不用看我下面的废话了。https://blog.52ipc.top/archives/149.html然后记录点自己解决的经验正式开始写一下我的优化过程:问题:MySQL查询count()from(括号里有七八个leftjoin),导致查询速度特别慢,结果大概是40s+1、......
  • 每日总结-23.4.12
    <%@pageimport="zhengcechaxun.Pd_zhengce"%><%@pageimport="zhengcechaxun.Thesql"%><%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%>&......
  • 2023.4.12——软件工程站立会议
    团队照片:站立会议内容:昨天做了什么?完成了团队第一阶段会议;今天要做什么?准备开始写具体代码实现;遇到什么问题?团队会议纪实和博客整理;......
  • R语言中的matrix(矩阵),list(列表),data.frame(数据框)总结
    一、R语言中的矩阵matrix是一个二维的数组array,因此数组array的一些操作它也适用。①它与array相比,特有的是矩阵的一些运算,例如:求维度:dim(A)转置:t(A)求行列式:det(A)矩阵相乘:x%*%y对角运算:diag(A)求逆:solve(A,b)求特征值和特征向量:eigen(A)奇异值分解:svd(A)②在多维数组中,apply函数......