Get the App
SLTechnology News&Howtos  ›  Database  › 

How to realize simple login and registration function in python and sqlite3 database

Shulou Source: shulou.com Published: 2022-05-31 12:41:53 10月05日 Update

This article will explain in detail about python and sqlite3 database how to achieve simple login and registration function, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

# coding=utf8# login registration features import wximport sqlite3class MyFrame (wx.Frame): def _ _ init__ (self): wx.Frame.__init__ (self, None,-1,'DB EXAMPLE',pos=wx.DefaultPosition,size= (300,150)) panel = wx.Panel (self,-1) usernameLabel = wx.StaticText (panel,-1) "user name:") # set user name Label self.usernameText = wx.TextCtrl (panel,-1, ", size= (175,1)) # set the text box self.usernameText.SetInsertionPoint (0) pwdLabel = wx.StaticText (panel,-1," password: ") # set Label self.pwdText = wx.TextCtrl (panel,-1,", size= (175) -1), style=wx.TE_PASSWORD) # text box for setting password loginButton=wx.Button (panel,-1, "login") # login button exitButton=wx.Button (panel,-1, "exit") # exit button registerButton=wx.Button (panel,-1, "registration") sizer = wx.FlexGridSizer (cols=2, hgap=6, vgap=6) # sizer setting sizer.AddMany ([usernameLabel, self.usernameText ") PwdLabel, self.pwdText,loginButton,exitButton,registerButton]) # install them all in sizer panel.SetSizer (sizer) self.Bind (wx.EVT_BUTTON, self.OnLogIn, loginButton) # login button bind event self.Bind (wx.EVT_BUTTON, self.OnCloseWindow, exitButton) # exit button bind event self.Bind (wx.EVT_BUTTON, self.OnRegister RegisterButton) # Registration button bind event # self.buildingDB () # create database and table This statement is only run for the first time Then comment it out with def OnLogIn (self) Event): # login method self.username=self.usernameText.GetValue () self.password=self.pwdText.GetValue () username=str (self.username.strip ()) conn=sqlite3.connect ('db01') cur=conn.cursor () cur.execute ("SELECT password FROM table01 WHERE username='%s'"% username) t=cur.fetchone () [0] print t if str (self.password) = = str (t): print 'Password is roomy' Self.Maximize (True) # window maximization Main interface else: print 'failed' def OnCloseWindow (self,event): # close window self.Close () # def loginmethod (self): # # pass def buildingDB (self): # build database conn=sqlite3.connect ("db01") cur=conn.cursor () cur.execute ("" CREATE TABLE table01 (username text) Password text, realname text,account text,workingdept text,phonenumber text) "") cur.execute ("INSERT INTO table01 values ('zhangsan','123','zhangsan','')") cur.execute ("INSERT INTO table01 values (' lisi','123','zhangsan','')") cur.execute ("INSERT INTO table01 values ('wangwu','123')") 'zhangsan','') ") conn.commit () cur.execute (" SELECT username FROM table01 WHERE username='zhangsan' "") # p=cur.fetchone () # print p cur.close () def OnRegister (self Event): # Registration method: self.username=self.usernameText.GetValue () self.password=self.pwdText.GetValue () conn=sqlite3.connect ("db01") cur=conn.cursor () cur.execute ("INSERT INTO table01 VALUES ('% swordline pageantry% swords pageantry')"% (self.username,self.password)) conn.commit () print "Registered successfully!" Cur.close () if _ _ name__ ='_ _ main__': app = wx.PySimpleApp () frame = MyFrame () frame.Show () app.MainLoop () about how to achieve simple login and registration in python and sqlite3 databases is shared here. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Buttons login data database function event password user name login content meaning text article method more knowledge article yes maximum Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Linux NVidia Shulou Technology Redmi