2

I am trying to make a basic login form. I'm having trouble with passing values to my function which checks the username and password.

Here is my code:

from tkinter import *

class Application(Frame):
    def __init__(self,master):
        super(Application, self).__init__(master)#Set __init__ to the master class
        self.grid()
        self.create_main()#Creates function

    def create_main(self):
        print("testing")
        self.title = Label(self, text=" Stuck In The Circle ")#TITLE 
        self.title.grid(row=0, column=2)

        self.user_entry_label = Label(self, text="Username: ")#USERNAME LABEL
        self.user_entry_label.grid(row=1, column=1)

        self.user_entry = Entry(self)                        #USERNAME ENTRY BOX
        self.user_entry.grid(row=1, column=2)

        self.pass_entry_label = Label(self, text="Password: ")#PASSWORD LABEL
        self.pass_entry_label.grid(row=2, column=1)

        self.pass_entry = Entry(self)                        #PASSWORD ENTRY BOX
        self.pass_entry.grid(row=2, column=2)

        self.sign_in_butt = Button(self, text="Sign In",command = self.logging_in)#SIGN IN BUTTON
        self.sign_in_butt.grid(row=5, column=2)

    def logging_in(self):
        print("hi")
        user_get = user_entry.get()#Retrieve Username
        pass_get = pass_entry.get()#Retrieve Password

        if user_get == 'sam':
            if pass_get == '123':
                print("Welcome!")






#Main
root = Tk()
root.title("Stuck in the Circle")
root.geometry("400x100")

app = Application(root)#The frame is inside the widgit
root.mainloop()#Keeps the window open/running

Here is my error:

Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\Sam\AppData\Local\Programs\Python\Python35-32\lib\tkinter_init_.py", line 1549, in call return self.func(*args) File "C:/Users/Sam/Desktop/Computer Science/Python/Python- Modules/Tkinter/Tkinter Projects/Login Form GUI.py", line 31, in logging_in user_get = user_entry.get()#Retrieve Username NameError: name 'user_entry' is not defined

2
  • Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\Sam\AppData\Local\Programs\Python\Python35-32\lib\tkinter_init_.py", line 1549, in call return self.func(*args) File "C:/Users/Sam/Desktop/Computer Science/Python/Python- Modules/Tkinter/Tkinter Projects/Login Form GUI.py", line 31, in logging_in user_get = user_entry.get()#Retrieve Username NameError: name 'user_entry' is not defined Commented Jan 21, 2016 at 19:34
  • Possible duplicate of How can I integrate TKinter with Python log in screen? Commented Feb 23, 2018 at 16:20

1 Answer 1

4
def logging_in(self):
    print("hi")
    user_get = self.user_entry.get()#Retrieve Username
    pass_get = self.pass_entry.get()#Retrieve Password

use self.user_entry.get()

When you are calling class variables, you need to call it by self.variable_name

Sign up to request clarification or add additional context in comments.

2 Comments

Thank-you so much man! I have been working on this for hours now and I feel so stupid! The code is all working like I wanted it to. I really appreciate your help :D Have a good day!
no problem :) please pick best answer when you get a chance!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.