In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
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.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.