Forums

Basic Login System - Saving User Input to .txt File

Hi there, new member here, I'm about a month into learning Python! I'm trying to create a basic login system using Tkinter, and am getting slightly stuck.

1) Using a register function, I'm trying to let the user create a username and password, however when I check the .txt file created it is blank. I've read that file.flush() will store the input into the file instantaneously, however it's still not there. I've tried variations with file.close() as well but it doesn't work for me.

2) Once the username and password has been entered, I need it to display a message confirming it was successful, so I can then move onto a login function.

So far, when I click 'Register', nothing happens. Below is the code I am currently using:

Any help is appreciated!

def register_user():
username_info = username.get()
password_info = username.get()

file = open("userinfo.txt", "w")
file.write(username_info+"\n")
file.write(password_info+"\n")
file.flush()
file.close()


new_username.delete(0, END)
new_password.delete(0, END)

Label(screen1, text="You're registered!", fg="green", font=("Calibri", 11)).pack()

sorry- is this something that you are trying to run on PythonAnywhere? you would not be able to use tkinter/create a button etc using tkinter on PythonAnywhere