介绍
这篇文章将为大家详细讲解有关python和sqlite3数据库如何实现简单登陆注册功能,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
“代码”类#=utf8编码 #登录注册功能齐了 import 天气 import sqlite3 class MyFrame (wx.Frame): ,,,def __init__(自我): ,,,,,,,wx.Frame.__init__(自我,,没有,,1,,& # 39;DB 示例# 39;,pos=wx.DefaultPosition大?(300,,150)) ,,,,,,,panel =, wx.Panel(自我,,1), ,,,,,,, ,,,,,,,usernameLabel =, wx.StaticText(面板,,1,,“用户名:“)#设置用户名标签 ,,,,,,,self.usernameText =, wx.TextCtrl(面板,,1,,,,,大?(175,1))#设置输入用户名的文本框 ,,,,,,,self.usernameText.SetInsertionPoint (0) ,,,,,,, ,,,,,,, ,,,,,,,pwdLabel =, wx.StaticText(面板,,1,,“密码:“)#设置密码的标签 ,,,,,,,self.pwdText =, wx.TextCtrl(面板,,1,,,,,,大?(175,1),风格=wx.TE_PASSWORD) #设置密码的文本框 ,,,,,,, ,,,,,,, ,,,,,,,loginButton=wx.Button(面板,1,“登录“)#登录按钮 ,,,,,,,exitButton=wx.Button(面板,1,“退出“)#退出按钮 ,,,,,,,registerButton=wx.Button(面板,1,“注册“) ,,,,,,, ,,,,,,,sizer =, wx.FlexGridSizer(关口=2,,hgap=6, vgap=6) #筛选器设置 ,,,,,,,sizer.AddMany ([self.usernameText, usernameLabel,还以为,pwdLabel, self.pwdText, loginButton, exitButton, registerButton]) #把它们都安在筛选器里 ,,,,,,,panel.SetSizer(筛选器) ,,,,,,, ,,,,,,,self.Bind (wx.EVT_BUTTON, self.OnLogIn,, loginButton) #登录按钮绑定事件 ,,,,,,,self.Bind (wx.EVT_BUTTON, self.OnCloseWindow,, exitButton) #退出按钮绑定事件 ,,,,,,,self.Bind (wx.EVT_BUTTON, self.OnRegister,, registerButton) #注册按钮绑定事件 ,,,,,,, ,,,,,,, ,,,,,,, ,,,,,,, #,,,,,,,,,self.buildingDB() #创建数据库和表,此语句只运行第一次,之后将其注释掉 ,,,,,,, ,,,def OnLogIn(自我、事件):#登录方法 ,,,,,,,self.username=self.usernameText.GetValue () ,,,,,,,self.password=self.pwdText.GetValue () ,,,,,,,用户名=str (self.username.strip ()) ,,,,,,,康涅狄格州=sqlite3.connect (& # 39; db01& # 39;) ,,,,,,,坏蛋=conn.cursor () ,,,,,,,cur.execute (“SELECT  password 得到table01 WHERE 用户名=& # 39;% & # 39;“%,用户名) ,,,,,,,t=cur.fetchone () [0] ,,,,,,,print t ,,,,,,,if str (self.password)==str (t): ,,,,,,,,,,,print & # 39; Password is 正确! & # 39; ,,,,,,,,,,,self.Maximize (True) #窗口最大化,意思意思主界面 ,,,,,,,其他的: ,,,,,,,,,,,print & # 39;失败# 39; ,,,def OnCloseWindow(自我、事件):#关闭窗口 ,,,,,,,self.Close () ,,,,,,, #,,,,,def loginmethod(自我): #,,,,,,,,, #,,,,,,,,, ,,,, ,,,def buildingDB(自我):#建立数据库 ,,,,,,,康涅狄格州=sqlite3.connect (“db01") ,,,,,,,坏蛋=conn.cursor () ,,,,,,,cur.execute (“““ null null null null null null null null null null null null null null null null null null null null null null null null null nullpython和sqlite3数据库如何实现简单登陆注册功能