我对Python非常陌生,因此毫无疑问有几个非常基本的错误,尽管我看过了一些Python教程,一切似乎都没问题。在
我正在尝试将两个文本文件导入到我的列表中。在
username.txt看起来像这样user1
user2
user3
而password.txt看起来像这样pass1
pass2
pass3
当我运行所有东西时,调试器不会给我任何错误,但当我尝试user/password组合时,它会说它是不正确的。在
你能看到什么不对劲的地方吗,或者知道什么有用的东西吗?在
这就是我正在运行的:from Tkinter import *
username = ["nathan"]
password = ["1"]
def login():
index = 0
usrnm = usernameEntry.get()
while index < len(username):
if username[index] == usrnm:
psswrd = passwordEntry.get()
if password[index] == psswrd:
print("Success")
break
else:
print("Password doesn't exist!")
break
else:
index = index + 1
else:
print("Username doesn't exist!")
def save():
fWUsername = open("username.txt", "w")
fWUsername.write("\n".join(str(x) for x in username))
fWUsername.close
fWPassword = open("password.txt", "w")
fWPassword.write("\n".join(str(x) for x in password))
fWPassword.close
def load():
fRUsername = open("username.txt", "r")
username = fRUsername.readlines()
fRUsername.close()
fRPassword = open("password.txt", "r")
password = fRPassword.readlines()
fRPassword.close()
loginForm = Tk()
usernameLabel = Label(loginForm, text = "username:")
usernameLabel.pack()
usernameEntry = Entry(loginForm)
usernameEntry.pack()
passwordLabel = Label(loginForm, text = "password:")
passwordLabel.pack()
passwordEntry = Entry(loginForm, show = "*")
passwordEntry.pack()
submitButton = Button(loginForm, text = "submit", command = login)
submitButton.pack()
loadButton = Button(loginForm, text = "load data lists", command = load)
loadButton.pack()
saveButton = Button(loginForm, text = "save data lists", command = save)
saveButton.pack()
mainloop()