求助:在wxpython中使用if 条件,运行结果不正确。求高手帮我,谢谢。
程序代码:
import wx import datetime num=19.2 class MyFrame(wx.Frame): def __init__(self,parent,id): wx.Frame.__init__(self,parent,id,'地铁充值',size=(280,300)) panel=wx.Panel(self) self.zhan=wx.StaticText(panel,label='请输站名') self.zhan1=wx.TextCtrl(panel,style=wx.TE_LEFT) hsize=wx.BoxSizer(wx.HORIZONTAL) hsize.Add(self.zhan,proportion=0,flag=wx.ALL,border=10) hsize.Add(self.zhan1,proportion=0,flag=wx.ALL,border=10) self.mony=wx.StaticText(panel,label='充值金额') self.mony1=wx.TextCtrl(panel,style=wx.TE_PROCESS_ENTER) self.Bind(wx.EVT_TEXT_ENTER, self.text_enter,self.mony1) hsize1=wx.BoxSizer(wx.HORIZONTAL) hsize1.Add(self.mony,proportion=0,flag=wx.ALL,border=10) hsize1.Add(self.mony1, proportion=0, flag=wx.ALL, border=10) self.jg=wx.StaticText(panel,label='',size=(150,250)) #hsize2=wx.BoxSizer(wx.HORIZONTAL) #hsize2.Add(self.jg,proportion=0,flag=wx.ALIGN_CENTER,border=5) vsize=wx.BoxSizer(wx.VERTICAL) vsize.Add(hsize,proportion=0,flag=wx.EXPAND|wx.LEFT|wx.RIGHT,border=5) vsize.Add(hsize1, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5) vsize.Add(self.jg, proportion=0, flag=wx.ALIGN_CENTER, border=5) panel.SetSizer(vsize) def text_enter(self,event): zha=self.zhan1.GetValue() mooy=self.mony1.GetValue() with open('aaa.txt','r',encoding='utf-8') as file: while True: lis=file.readline() if not lis: break else: qq=lis.split('|') bb=qq[0] cc=qq[1] dd=qq[2] if bb==zha: wjx=f'车站名称:{bb}\n设备编号:{cc}\n票卡编号:{dd}\n' #''.format(dd) #'充值时间:', datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') #'充前余额:{}'.format(num) #'充值额是:{}'.format(mooy) #'当前余额:{}'.format(num + mooy)) self.jg.SetLabel(wjx) else: py = "站名输入错误,请重新输入" self.jg.SetLabel(py) self.zhan1.SetValue("") self.mony1.SetValue("") if __name__ == '__main__': app=wx.App() frame=MyFrame(parent=None,id=-1) frame.Show() app.MainLoop()