Reputation: 154
I created a program which should dump the username and password in json file
But i am having problem in solving it
plz help
def createAccount():
A = tk.StringVar()
B = tk.StringVar()
root1 = Tk()
root1.resizable(0, 0)
root1.title('Signup')
instruction = Label(root1, text='Please Enter new Credentials')
instruction.grid(row=0, column=0, sticky=E)
nameL = Label(root1, text='New Username: ')
pwordL = Label(root1, text='New Password: ')
nameL.grid(row=1, column=0, sticky=W)
pwordL.grid(row=2, column=0, sticky=W)
nameE = Entry(root1, textvariable=A)
pwordE = Entry(root1, textvariable=B )
nameE.grid(row=1, column=1)
pwordE.grid(row=2, column=1)
signupButton = Button(root1, text='Signup')
signupButton.grid(columnspan=2, sticky=W)
root1.mainloop()
username = A
password = B
with open('user_accounts.json', 'r+') as user_accounts:
users = json.load(user_accounts)
if username in users.keys():
print('error')
else:
users[username] = [password, "PLAYER"]
user_accounts.seek(0)
json.dump(users, user_accounts)
user_accounts.truncate()
print("success")
I tried to convert username and password into string by using tk.StringVar()
Plz provide any appropriate solution
Upvotes: 1
Views: 61
Reputation: 1064
tkinter labels don't use normal Python variables types. Instead, they use tcl types, such as StringVar
. to get the values of such variables, you can call their .get()
method, which returns a native Python value. Now you can convert, change and use it as you like :)
Upvotes: 1