In an attempt to make a program that takes a username and password given by the user and then loads that document, I've encountered an odd error
load_user() missing 1 required positional argument: 'username'
but it has been passed this by the user. I'll include the full code below, but the area where the issue may lie is the unfinished load function, I think:
def load_user(self,username):
print("...")
jj = open("data_"+str(username)+".txt","r")
lines = jj.readlines()
user = str(lines[2])
passw = str(lines[4])
print("...")
if password == passw:
print("Loaded save of "+user)
Like I say, the entire body of the class is included below just in case it is an issue in another area.
All help is appreciated, thanks!
EDIT: To clarify, I need the command to execute when the button is pressed, so passing self.load_user(...) doesn't work, as it executes when Tkinter opens.
from tkinter import *
get = 0
class Menu_F:
def __init__(self,master):
frame = Frame(master)
frame.grid()
title_username = Label(master, text="User Name")
title_username.grid(row=0, column=0)
title_password = Label(master, text="Password")
title_password.grid(row=1, column=0)
global username
username = Entry(master, bd=5)
username.grid(row=0, column=1)
global password
password = Entry(master, bd=5, show="*")
password.grid(row=1, column=1)
load_game = Button(master, text="Load Game",
fg="black",command=self.load_user)
load_game.grid(row=3, column=1)
new_game = Button(master, text="New Game",
fg="black",command=self.new_user)
new_game.grid(row=3, column=0)
confirm_username = Button(master, text="Done",
fg="black",command=self.get_username)
confirm_username.grid(row=0, column=2)
confirm_password = Button(master, text="Done",
fg="black",command=self.get_password)
confirm_password.grid(row=1, column=2)
def get_username(self):
get = 1
global username
username = username.get()
print("Username is: "+username)
def get_password(self):
global password
password = password.get()
print("Password is: "+password)
def load_user(self,username):
print("...")
jj = open("data_"+str(username)+".txt","r")
lines = jj.readlines()
user = str(lines[2])
passw = str(lines[4])
print("...")
if password == passw:
print("Loaded save of "+user)
def save_user(self,username,password,progress):
ss = open("data_"+str(username)+".txt","w")
ss.write("""_-_-_
-_-_-
"""+str(username)+"""
_-_-_
"""+str(password)+"""
-_-_-
"""+int(progress))
def new_user(self,username,password):
nn = open("data_"+str(username)+".txt","w")
nn.write("""_-_-_
-_-_-
"""+str(username)+"""
_-_-_
"""+str(password)+"""
-_-_-
0""")
root = Tk()
root.resizable(width=FALSE, height=FALSE)
app = Menu_F(root)
mainloop()