我想创建一个登录,其中将打开一个文本/csv文件,从文件中读取“有效”的用户名和密码,然后如果用户添加的内容与文件中的内容匹配,那么它将允许访问程序的其余部分
如何将下面的代码集成到其中一个文件中打开一个文件,读取有效的用户名和密码,并根据用户的输入进行检查
目前我有一些工作,但只有一个密码,我已设置在代码。在Password = StringVar()
Username = StringVar()
def EnterPassword():
file = open('Logins.txt', 'w') #Text file i am using
with open('Logins.txt') as file:
data = file.read() #data=current text in text file
UsernameAttempt = Username.get()#how to get value from entry box
PasswordAttempt = Password.get()#how to get value from entry box
if PasswordAttempt == '' and UsernameAttempt == '':
self.delete()
Landlord = LandlordMenu()
else:
PasswordError = messagebox.showerror('Password/Username Entry','Incorrect Username or Password entered.\n Please try again.')
PasswordButton = Button(self.GenericGui,text = 'Landlord Section',height = 3, width = 15, command = EnterPassword, font = ('TkDefaultFont',14),relief=RAISED).place(x=60,y=175)
如有帮助,将不胜感激