python里面if语句一直出错_python错误,写了个小程序,if语句总是不执行,求高手指点...

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()

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值