I'm very very new to Python so no doubt there are several very basic mistakes, although I have looked through several Python tutorials and everything seems ok.
I'm trying to import two text files in to my list.
The username.txt looks like this
user1
user2
user3
and the password.txt looks like this
pass1
pass2
pass3
when I run everything the debugger doesn't give me any errors but when I try a user/password combination it says that it isn't correct.
Can you see anything wrong, or know anything that might help?
This is what I am running:
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()
print usernameafterusername = fRUsername.readlines()and see if the format is as you expect.strip()