Home > database >  Error text input entry and get() entry input
Error text input entry and get() entry input

Time:10-22

have getting confused in getting the value from the Tkinter() Entry Field. I have this kind of code...

    def login():
root_login = Tk()
root_login.title("Login")
root_login.geometry("400x400")

label_text_name = Label(root_login, text="Type mail your :")
label_text_name.pack()
label_text_name.place(x=25, y=50)
label_text_token = Label(root_login, text="Type Pasword :" )
label_text_token.pack()
label_text_token.place(x=58, y=150)

input_text_email = Entry(root_login, width=30)
input_text_email.pack()
input_text_email.place(x=150, y=50)

input_text_token = Entry(root_login, width=30)
input_text_token.pack()
input_text_token.place(x=150, y=150)

e1 = Entry(root_login)
e1.pack()
btn_login = Button(root_login,command=after_login, text="Login", height=1, width=10 )
btn_login.pack()
btn_login.place(x=50, y=250)

def after_login():
     var = e1.get()     
     messagebox.showinfo(var1)

but i get a error !

var = e1.get() NameError: name 'e1' is not defined

CodePudding user response:

This is because your after_login function doesn't know what e1 is, since it's defined outside of the functions scope. You have to modify your code, maybe by setting the variable as global ( Which can lead to other problems if done incorrectly ) or some other way let after_login know what an e1 is ( by maybe giving it as parameter could solve this? )

CodePudding user response:

Jimpsoni, I have put in a global vatable like this:

def login():
root_login = Tk()
root_login.title("Login")
root_login.geometry("400x400")

label_text_name = Label(root_login, text="Type mail your :")
label_text_name.pack()
label_text_name.place(x=25, y=50)
label_text_token = Label(root_login, text="Type Pasword :" )
label_text_token.pack()
label_text_token.place(x=58, y=150)

input_text_email = Entry(root_login, width=30)
input_text_email.pack()
input_text_email.place(x=150, y=50)

input_text_token = Entry(root_login, width=30)
input_text_token.pack()
input_text_token.place(x=150, y=150)

global var1
var1 = input_text_token.get()

btn_login = Button(root_login,command=after_login, text="Login", height=1, width=10 )
btn_login.pack()
btn_login.place(x=50, y=250)

def after_login():
         
     messagebox.showinfo(var1)

but now I get this error!

    global var1
           ^

IndentationError: unindent does not match any outer indentation level

  • Related