*First of all, i am trying to create a register system saved into textfile(not real system, i know its not safe to write into textfiles) Created the GUI and then i defined multiple functions which is Menu, register and submit. Submit function is nested and inside register function. The problem is when i nested the functions it doesn't write into textfiles, but when i delete the register function, it works. When i press register and write something in the Entry box, it didnt record to the text files, i have been scratching my head as to find what the error in my code is.
Edit: I now have put a picture to get better understanding. the blue window is main menu and its the mainloop and the yellow window is appearing when i click register button.*
picture of what should be my app
from tkinter import *
def Register():
def Submit():
elev = open("bruker.txt","a", encoding="utf-8")
elev.write(brukeridinc.get()+"\n")
elev.write(fornavn.get()+"\n")
elev.write(etternavn.get()+"\n")
register = Tk()
register.geometry("500x500")
register.configure(bg="yellow")
register.title("Bibliotekapp Login")
label_brukerid = Label(register, text="Brukerid:", bg="white", font=("Arial", 25))
label_brukerid.grid(row=1, column=0, padx=5, pady=5, sticky=E)
label_fornavn = Label(register, text="Fornavn:", bg="white", font=("Arial", 25))
label_fornavn.grid(row=2, column=0, padx=5, pady=5, sticky=E)
label_etternavn = Label(register, text="Etternavn:", bg="white", font=("Arial", 25))
label_etternavn.grid(row=3, column=0, padx=5, pady=5, sticky=E)
brukeridinc= StringVar()
entry_brukerid= Entry(register, width=10, textvariable=brukeridinc, font=("Arial", 25))
entry_brukerid.grid(row=1, column=1, padx=5, pady=5, sticky=W)
fornavn= StringVar()
entry_fornavn= Entry(register, width=10, textvariable=fornavn, font=("Arial", 25))
entry_fornavn.grid(row=2, column=1, padx=5, pady=5, sticky=W)
etternavn= StringVar()
entry_etternavn= Entry(register, width=10, textvariable=etternavn, font=("Arial", 25))
entry_etternavn.grid(row=3, column=1, padx=5, pady=5, sticky=W)
button_resultat= Button(register, text="Enter", command=Submit, height=2, width=15)
button_resultat.grid(row=4, column=1, padx=5, pady=5, sticky=W)
informasjon= StringVar()
entry_informasjon= Entry(register, width=24, textvariable=informasjon, state="readonly", font=("Arial", 25))
entry_informasjon.grid(row=5, column=1, padx=5, pady=5, sticky=W)
#GUI
start = Tk()
start.geometry("500x500")
start.configure(bg="lightblue")
start.title("Bibliotekapp")
button_register = Button(start, text="Register", bg="white", font=("Arial", 25), command=Register)
button_register.grid(row=5, column=5, padx=5, pady=5, sticky=E)
start.mainloop()
start
is a local variable insidemenu()
, so how can you callstart.mainloop()
outside the function?