mardi 8 juin 2021

If statement to check if the value of a variable is in a JSON file

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 LI
    passwords = players['password']
KeyError: 'password'



Aucun commentaire:

Enregistrer un commentaire