import wx import pymysql, threading, time from MySQL import function class Gaim1(wx.App): def doClose(self, j): time.sleep(j) self.frame.Close() def __init__(self, YuanZhangH): self.YuanZhangH = YuanZhangH wx.App.__init__(self) self.frame = wx.Frame(parent=None, title='修改密码', size=(535, 450), style=wx.DEFAULT_FRAME_STYLE ^ wx.RESIZE_BORDER ^ wx.MAXIMIZE_BOX) panel = wx.Panel(self.frame, -1) panel.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBack) label_user = wx.StaticText(panel, -1, "密 码:", pos=(80, 160)) label_pass = wx.StaticText(panel, -1, "确认密码:", pos=(80, 215)) self.mim = wx.TextCtrl(panel, -1, size=(250, 35), pos=(140, 150), style=wx.TE_PASSWORD) # style 为设置输入 self.qmim = wx.TextCtrl(panel, -1, size=(250, 35), pos=(140, 205), style=wx.TE_PASSWORD) self.QueDing_button = wx.Button(panel, -1, "修 改", size=(80, 60), pos=(120, 280)) self.QuXiao_button = wx.Button(panel, -1, "返 回", size=(80, 60), pos=(340, 280)) self.QueDing_button.SetBackgroundColour('#0a74f7') self.QuXiao_button.SetBackgroundColour('#0a74f7') self.Bind(wx.EVT_BUTTON, self.Xiu, self.QueDing_button) self.Bind(wx.EVT_BUTTON, self.QU, self.QuXiao_button) self.frame.Center() self.frame.Show(True) def show_message(self, word=""): dlg = wx.MessageDialog(None, word, u"错误", wx.YES_NO | wx.ICON_QUESTION) if dlg.ShowModal() == wx.ID_YES: # self.Close(True) pass dlg.Destroy() def show_check(self, word=""): dlg = wx.MessageDialog(None, word, u"提示", wx.YES_NO | wx.ICON_QUESTION) if dlg.ShowModal() == wx.ID_YES: # self.Close(True) pass dlg.Destroy() def Xiu(self, event): YuanZhangH = self.YuanZhangH z1 = self.mim.GetValue() z2 = self.qmim.GetValue() sql = "update card set password = '{}' where Card_Number = '{}'".format(z1, YuanZhangH) if z1 and z2: db = pymysql.connect(host="localhost", user="root", password="lwh20021210...", db="atm", port=3306) # 使用cursor()方法获取操作游标 cur = db.cursor() try: if z1 == z2: cur.execute(sql) # 执行sql语句 db.commit() self.show_check(word='密码修改成功') results = cur.fetchall() # 获取查询的所有记录 # 返回值是一个元组的形式 else: self.show_message(word='请确保两次输入密码相同') except Exception as e: db.rollback() finally: db.close() # 关闭连接 pass def OnEraseBack(self, event): dc = event.GetDC() if not dc: dc = wx.ClientDC(self) rect = self.GetUpdateRegion().GetBox() dc.SetClippingRect(rect) dc.Clear() bmp = wx.Bitmap('img\\instagram.jpg') dc.DrawBitmap(bmp, 0, 0) def QU(self, event): t = threading.Thread(target=self.doClose, args=(0.05,)) t.start() jie = function.Jiemian(self.YuanZhangH) jie.MainLoop()