gtk3 + sqlite3实现登录注册(前后端分离)




import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
import sqlite3
 
class LoginRegisterWindow(Gtk.Window):
    def __init__(self):
        super().__init__(title="Login and Register")
        self.set_default_size(400, 200)
 
        # 创建一个水平盒布局
        box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10)
 
        # 创建登录面板
        self.login_panel = LoginPanel(self)
        box.pack_start(self.login_panel, True, True, 0)
 
        # 创建注册面板
        self.register_panel = RegisterPanel(self)
        box.pack_start(self.register_panel, True, True, 0)
 
        # 将盒布局添加到窗口
        self.add(box)
 
class LoginPanel(Gtk.Box):
    def __init__(self, parent):
        super().__init__(orientation=Gtk.Orientation.VERTICAL, spacing=10)
 
        # 用户名和密码输入
        self.entry_username = Gtk.Entry()
        self.entry_password = Gtk.Entry()
        self.entry_password.set_visibility(False)
 
        # 登录按钮
        self.button_login = Gtk.Button(label="Login")
        self.button_login.connect("clicked", self.on_login_clicked)
 
        # 添加到登录面板
        self.pack_start(Gtk.Label(label="Username"), False, False, 0)
        self.pack_start(self.entry_username, False, False, 0)
        self.pack_start(Gtk.Label(label="Password"), False, False, 0)
        self.pack_start(self.entry_password, False, False, 0)
        self.pack_start(self.button_login, False, False, 0)
 
        self.parent = parent
 
    def on_login_clicked(self, widget):
        username = self.entry_username.get_text()
        password = self.entry_password.get_text()
        if self.validate_login(username, password):
            self.parent.set_title("Welcome, %s!" % username)
            # 这里可以添加进入主界面的代码
 
    def validate_login(self, username, password):
        # 连接数据库并检查凭据
        conn = sqlite3.connect('users.db')
        cursor = conn.cursor()
        cursor.execute("SELECT * FROM users WHERE username=? AND password=?", (username, password))
        if cursor.fetchone():
            conn.close()
            return True
        else:
            conn.close()
            self.entry_username.set_text("")
            self.entry_password.set_text("")
            return False
 
class Regis
sql
最后修改于:2024年09月02日 09:58

评论已关闭

推荐阅读

Vue中使用mind-map实现在线思维导图
2024年08月04日
VUE
Web前端最全Vue实现免密登录跳转的方式_vue怎么样不登录返回首页,最强技术实现
2024年08月04日
VUE
vue3 项目搭建教程(基于create-vue,vite,Vite + Vue)
2024年08月04日
VUE
Vue-颜色选择器实现方案——>Vue-Color( 实战*1+ Demo*7)
2024年08月04日
VUE
Vue项目卡顿慢加载?这些优化技巧告诉你!_vue数据多渲染卡顿
2024年08月04日
VUE
vue中的keep-alive详解与应用场景
2024年08月04日
VUE
Vue、React实现excel导出功能(三种实现方式保姆级讲解)
2024年08月04日
vue-office/docx插件实现docx文件预览
2024年08月04日
VUE
java调用js文件的两种方法(支持V8引擎)
2024年08月04日
JavaScript:解决计算精度问题/mathjs/bignumber.js/big.js/decimal.js
2024年08月04日
两周从爬虫小白变大神 _yjs_js_security_passport
2024年08月04日
JS笔记(对象、函数、数组)
2024年08月04日
Markdown.js:强大的纯JavaScript Markdown解析器
2024年08月04日
Vue项目:js模拟点击a标签下载文件并重命名,URL文件地址下载方法、请求接口下载文件方法总结。
2024年08月04日
vue 父组件怎么获取子组件里面的data数据
2024年08月04日
VUE
个人开发实现AI套壳网站快速搭建(Vue+elementUI+SpringBoot)
2024年08月04日
el-table 表格封装并改造实现单元格可编辑
2024年08月04日
none
nodejs环境下创建vue项目、SSH密钥登陆!!!
2024年08月04日
vue+quill+element-ui实现视频、图片上传及缩放保姆级教程,轻松使用富文本
2024年08月04日
【three.js】22. Imported Models导入模型
2024年08月04日