'I wanted sigup button to give the value to my funtion which writes the value in json but I don't know how to
def signup_page(filename="accounts.json"):
top = Toplevel()
top.title("Sign up page")
top.geometry('700x600')
top.resizable(False,False)
signup_label = Label(top,text="Create a account",font=("Bold",15))
signup_label.grid(column=5,row=0, pady=0, padx=20, sticky="wens")
namelabel = Label(top, text="Enter your name here : ")
namelabel.grid(row=4,column=0,pady=10)
e = Entry(top, width=20)
e.grid(column=1,row=4,padx=0,pady=10,columnspan=4)
gmaillabel = Label(top, text="Enter your gmail here : ")
gmaillabel.grid(row=5,column=0,pady=10)
e1 = Entry(top, width=20)
e1.grid(column=1,row=5,padx=0,pady=10,columnspan=4)
address = Label(top, text="Enter your address here : ")
address.grid(row=6,column=0,pady=10)
e2 = Entry(top, width=50)
e2.grid(column=1,row=6,padx=0,pady=10,columnspan=50)
phone_number = Label(top, text="Enter your address here : ")
phone_number.grid(row=7,column=0,pady=10)
e3 = Entry(top, width=20)
e3.grid(column=1,row=7,padx=0,pady=10,columnspan=4)
create_pin = Label(top, text="Enter your pin here(only numbers) : ")
create_pin.grid(row=8,column=0,pady=10)
e4 = Entry(top, width=20)
e4.grid(column=1,row=8,padx=0,pady=10,columnspan=4)
confirm_password = Label(top, text="confirm your pin : ")
confirm_password.grid(row=9,column=0,pady=10)
e5 = Entry(top, width=20)
e5.grid(column=1,row=9,padx=0,pady=10,columnspan=4)
ID = Label(top, text="Enter your ID here : ")
ID.grid(row=10,column=0,pady=10)
e6 = Entry(top, width=20)
e6.grid(column=1,row=10,padx=0,pady=10,columnspan=4)
signup_button = Button(top, text="Create account")
signup_button.grid(row=11,column=5,pady=0,padx=20,sticky='wens')
this is the code of the sign up window and I wanted the sign up button to give the values to the functions below but I cannot return the value using command=
def write_json(data,filename="accounts.json"):
with open(filename,"w") as f:
json.dump(data,f,indent=4)
def acc_create(filename="accounts.json"):
with open(filename) as jf:
data = json.load(jf)
temp = data["users"]
y = {e6.get():{"gmail":e1.get(),"name":e.get(),"address":e2.get(),"phn":e3.get(),"balance":0,"pin":e5.get()}}
temp.append(y)
write_json(data)
print("Account succesfully created")
and these are the functions that is I use to write the data in the json file
Solution 1:[1]
ok imade it work using lambda i tried to use partial but i guess it only takes one argument
signup_button = Button(top, text="Create account",command=lambda: acc_create(e.get(),e1.get(),e2.get(),e3.get(),e4.get(),e6.get()))
signup_button.grid(row=11,column=5,pady=0,padx=20,sticky='wens')
this is how i returned values from the button
def acc_create(a,b,c,d,e,f,filename="accounts.json"):
with open(filename) as jf:
data = json.load(jf)
temp = data["users"]
y = {f:{"gmail":b,"name":a,"address":c,"phn":d,"balance":0,"pin":e}}
temp.append(y)
write_json(data)
print("Account succesfully created")
and here is how I accepted the values in this function
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
