I'm kind of new so try not to judge me. I'm trying to create a little 2d game based on the old 2d Mario. I already have home window, the sign up and login windows, and I've got a json file to save the usernames and passwords. Now, I'm trying to get the login function to work. The problem seems to be this line:
if plpaword in players['password']
This should help you understand what the variables stand for
f = open('player.json')
players = json.load(f)
plpaword = E2.get()
When I run my code, everything else seems to work fine until I try to log in. After logging in, it should create a new window, but what happens is nothing happens and it gives the error:
Exception in Tkinter callback
Traceback (most recent call last):File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py", line 1883, in __call__return self.func(*args)File "/Users/kevin/PycharmProjects/ANewFile/ANewFile.py", line 101, in LIpasswords = players['password']
KeyError: 'password'
I used these modules:
from tkinter import *
import tkinter
import tkinter.messagebox
from tkinter import messagebox
from tkinter import Tk, Button, Frame, Entry, END
import random
import json
Creating an account and saving it to my player.json file:
def SU():try:plusname = E1.get()plpaword = E2.get()plpaword2 = E3.get()plemail = E4.get()if plpaword == plpaword2:if plusname in players:messagebox.showerror(random.choice(error), "An account with that username already exists. ""Please choose another.")else:players[plusname] = {'password': plpaword, 'email': plemail}with open('player.json', 'w') as f:json.dump(players, f)signup.destroy()messagebox.showinfo("Account Created!", "Please log in to your new account through log in.")else:messagebox.showerror(random.choice(error), "Passwords did not match. Please try again")except:messagebox.showerror(random.choice(error), random.choice(errormsg))