python和sqlite3数据库初探(简单登陆注册功能)
2013-05-13 16:50
381 查看
#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, "用户名:")#设置用户名Label self.usernameText = wx.TextCtrl(panel, -1, "",size=(175, -1))#设置输入用户名的文本框 self.usernameText.SetInsertionPoint(0) pwdLabel = wx.StaticText(panel, -1, "密码:")#设置密码的Label self.pwdText = wx.TextCtrl(panel, -1, "", size=(175, -1),style=wx.TE_PASSWORD)#设置密码的文本框 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设置 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()#创建数据库和表,此语句只运行第一次,之后将其注释掉 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):#关闭窗口 self.Close() # def loginmethod(self): # # pass def buildingDB(self):#建立数据库 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()
相关文章推荐
- Struts2和hibernate框架整合实现简单的注册登陆功能
- 利用python实现简单登陆注册系统
- Python学习笔记_02:使用Tkinter连接MySQL数据库实现登陆注册功能
- 【django4】简单注册/登陆/注销功能
- SpringBoot实现简单的注册与登陆功能
- 基于Struts2和Android的简单登陆注册功能的设计与实现(待完善)
- SpringBoot+thymeleaf简单实现登陆注册及记账功能
- 【PythonDjango后台实例 第六章】Django实现简单的登陆验证功能
- JAVA简单链接Oracle数据库 注册和登陆功能的实现代码
- Python Flask开发之注册登陆功能
- Eclipse使用(七)—— 使用Eclipse创建JavaWeb项目并使用JDBC连接数据库实现简单的登陆注册功能
- 用正则表达式简单实现邮箱登陆注册等功能
- Android SharedPreferences应用 实现本地注册登陆 功能简单易懂(实例)
- JAVA简单链接Oracle数据库,实现注册和登陆的功能
- jsp+servlet+ajax+oracle数据库-实现简单的登陆、注册、找回密码功能(与Oralce数据库连接)
- 1_python小程序之实现用户的注册登陆验证功能
- python django -- 简单注册/登陆/session
- C语言实现简单注册登陆功能
- Android 实现简单的登陆注册功能(SharedPreferences和SQLite)
- [python] 字典运用:注册登陆系统