python错误,写了个小程序,if语句总是不执行,求高手指点 10

importwximportMySQLdbclassadddialog(wx.Frame):def__init__(self):self.frame=wx.Frame._... 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()
展开
 我来答
帐号已注销
2012-04-12 · TA获得超过158个赞
知道小有建树答主
回答量:122
采纳率:0%
帮助的人:120万
展开全部
n=self.addname.GetValue()返回的是unicode
r=cur.fetchall()返回的是包含str(不是unicode)的list
转换下编码哈。
追问
我转换了一下,还是不对,您能指点一下吗?直接给些个转换代码更好,我刚接触,什么都不懂
r=cur.execute('select usernumber from user')
r=cur.fetchall()
ns=[]
for rec in r:
ns.append(rec)
if n in ns:
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
pythonhome
2012-04-05 · TA获得超过233个赞
知道小有建树答主
回答量:288
采纳率:0%
帮助的人:210万
展开全部
执行触发事件了吗?有错误提示吗?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式