importwximportMySQLdbclassadddialog(wx.Frame):def__init__(self):self.frame=wx.Frame.__init__(self,None,-1,'添加',size=(300,300))panel=wx.Panel(self,-1)label4=wx.StaticTex...
import wx
import MySQLdb
class adddialog(wx.Frame):
def __init__(self):
self.frame=wx.Frame.__init__(self,None,-1,'添加',size=(300,300))
panel=wx.Panel(self,-1)
label4=wx.StaticText(panel,-1,'用户名',pos=(10,10))
self.addname=wx.TextCtrl(panel,-1,pos=(100,10),size=(160,-1))
label5=wx.StaticText(panel,-1,'密码',pos=(10,40))
self.addpassword=wx.TextCtrl(panel,-1,'1234',pos=(100,40),size=(160,-1),style=wx.TE_PASSWORD)
self.button3=wx.Button(panel,-1,'添加',pos=(50,200))
self.button4=wx.Button(panel,-1,'取消',pos=(150,200))
self.Bind(wx.EVT_BUTTON, self.OnButton3, self.button3)
self.Bind(wx.EVT_BUTTON, self.OnButton4, self.button4)
def OnButton3(self,event):
n=self.addname.GetValue()
p=self.addpassword.GetValue()
db=MySQLdb.connect(host='localhost',user='root',
passwd='jinlong',db='python')
cur=db.cursor()
cur.execute("insert into user (usernumber,password) values('%s','%s')"%(n,p))
db.commit()
r=cur.execute('select usernumber from user')
r=cur.fetchall()
if n in r:
wx.MessageBox('用户已存在!', '提示信息', wx.OK|wx.ICON_INFORMATION)
else:
dlgOk=wx.MessageBox('添加成功!', '提示信息', wx.OK|wx.ICON_INFORMATION)
cur.close()
db.close()
self.Close()
def OnButton4(self,event):
self.Close()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame=adddialog()
frame.Show(True)
app.MainLoop()
展开