“关于两个字符串内容一样python却说不一样的事”
截图:
代码:
# -*- coding:utf-8 -*-
import sys
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, title='Login', size=(400, 300))
panel = wx.Panel(self)
self.title = wx.StaticText(panel, label='Input username and password', pos=(120, 20))
self.label_user = wx.StaticText(panel, label='Username', pos=(40, 50))
self.text_user = wx.TextCtrl(panel, size=(235, 25), pos=(100, 50), style=wx.TE_LEFT)
self.label_pwd = wx.StaticText(panel, label='Password', pos=(40, 90))
self.text_password = wx.TextCtrl(panel, size=(235, 25), pos=(100, 90), style=wx.TE_PASSWORD)
self.bt_confirm = wx.Button(panel, label='Confirm', pos=(150, 130))
self.bt_confirm.Bind(wx.EVT_BUTTON, self.OnclickSubmit)
self.bt_cancel = wx.Button(panel, label='Cancel', pos=(255, 130))
self.bt_cancel.Bind(wx.EVT_BUTTON, self.OnclickCancel)
self.bt_registered = wx.Button(panel, label='Register', pos=(45, 130))
self.bt_registered.Bind(wx.EVT_BUTTON, self.OnclickRegister)
def OnclickRegister(self, ever):
pass
def OnclickSubmit(self, even):
file = open('res/information.txt', 'r')
users = file.readlines()
for i in users:
username = self.text_user.GetValue()
password = self.text_password.GetValue()
style = username + ';' + password
print(i + '\n' + str(type(i)))
print(style + '\n' + str(type(style)))
if username == '' or password == '':
wx.MessageBox('Username and password cannot be null.')
elif users == style:
wx.MessageBox('Login succeeded.')
else:
wx.MessageBox('Username and password do not match')
break
file.close()
def OnclickCancel(self, event):
sys.exit(0)
if __name__ == '__main__':
app = wx.App()
frame = MyFrame(parent=None, id=-1)
frame.Show()
app.MainLoop()
在当前目录下的res文件夹里还有一个information.txt,其内容为:
root;root
气人!