這篇文章將為大家詳細(xì)講解有關(guān)python和sqlite3數(shù)據(jù)庫如何實(shí)現(xiàn)簡單登陸注冊功能,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

#coding=utf8
#登錄注冊功能齊了
import wx
import sqlite3
class 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, "用戶名:")#設(shè)置用戶名Label
self.usernameText = wx.TextCtrl(panel, -1, "",size=(175, -1))#設(shè)置輸入用戶名的文本框
self.usernameText.SetInsertionPoint(0)
pwdLabel = wx.StaticText(panel, -1, "密碼:")#設(shè)置密碼的Label
self.pwdText = wx.TextCtrl(panel, -1, "", size=(175, -1),style=wx.TE_PASSWORD)#設(shè)置密碼的文本框
loginButton=wx.Button(panel,-1,"登錄")#登錄按鈕
exitButton=wx.Button(panel,-1,"退出")#退出按鈕
registerButton=wx.Button(panel,-1,"注冊")
sizer = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)#sizer設(shè)置
sizer.AddMany([usernameLabel, self.usernameText, pwdLabel, self.pwdText,loginButton,exitButton,registerButton])#把它們都安在sizer里
panel.SetSizer(sizer)
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()#創(chuàng)建數(shù)據(jù)庫和表,此語句只運(yùn)行第一次,之后將其注釋掉
def OnLogIn(self,event):#登錄方法
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 correct!'
self.Maximize(True)#窗口較大化,意思意思主界面
else:
print 'failed'
def OnCloseWindow(self,event):#關(guān)閉窗口
self.Close()
# def loginmethod(self):
#
# pass
def buildingDB(self):#建立數(shù)據(jù)庫
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):#注冊方法
self.username=self.usernameText.GetValue()
self.password=self.pwdText.GetValue()
conn=sqlite3.connect("db01")
cur=conn.cursor()
cur.execute("INSERT INTO table01 VALUES('%s','%s','','','','')"%(self.username,self.password))
conn.commit()
print "Registered successfully!"
cur.close()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()關(guān)于python和sqlite3數(shù)據(jù)庫如何實(shí)現(xiàn)簡單登陸注冊功能就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
網(wǎng)站欄目:python和sqlite3數(shù)據(jù)庫如何實(shí)現(xiàn)簡單登陸注冊功能-創(chuàng)新互聯(lián)
文章地址:http://chinadenli.net/article12/eopdc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、網(wǎng)站建設(shè)、動(dòng)態(tài)網(wǎng)站、網(wǎng)站導(dǎo)航、響應(yīng)式網(wǎng)站、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)