NameError: name 'first' is not defined What Can I Do?

python nameerror: name is not defined function
nameerror: name 'value is not defined
nameerror: name temp is not defined
nameerror: name is not defined python class
how to resolve name error in python
nameerror: name success is not defined
nameerror name '_name_' is not defined
nameerror: name 'y' is not defined
from tkinter import *
root = Tk()
root.geometry("400x400")
root.title("Bubble Sort")

def printfirst():
    get1 = w.get()
    get2 = e.get()
    get3 = r.get()
    get4 = t.get()
    get5 = y.get()
    first = Label(root, text= get1 + get2 + get3 + get4 + get5)
    first.pack()

def test():
    get1 = w.get()
    get2 = e.get()
    get3 = r.get()
    get4 = t.get()
    get5 = y.get()
    if get1 > get2:
        first.configure(text= get2 + get1 + get3 + get4 + get5)

te = Label(root, text="Enter 5 Diffrent Numbers")
te.pack()
w = Entry(root)
get1 = w.get()
w.pack()
e = Entry(root)
get2 = e.get()
e.pack()
r = Entry(root)
get3 = r.get()
r.pack()
t = Entry(root)
get4 = t.get()
t.pack()
y = Entry(root)
get5 = y.get()
y.pack()
p = Button(root, text="Print Out", command=printfirst)
p.pack()

gg = Button(root, text="Sort It!", command=test)
gg.pack()

root.mainloop()

The error log:

"Exception in Tkinter callback Traceback (most recent call last): File "C:\Python34\lib\tkinter__init__.py", line 1533, in call return self.func(*args) File "C:/Users/lycelab18/Desktop/testt.py", line 29, in test first.configure(text= get2 + get1 + get3 + get4 + get5) NameError: name 'first' is not defined"


In your test() function you use first.configure(...) before you define first var.

You first value defined in printfirst() doen't exist in test() function.

input() error - NameError: name '' is not defined, TL;DR. input function in Python 2.7, evaluates whatever your enter, as a Python expression. If you simply want to read strings, then use  Join the world's most active Tech Community! Welcome back to the World's most active Tech Community!


The variable first only exists within the scope of the function printfirst(), this means you can't access it from within the scope of test().

One way to solve this is to return first from the printfirst() function, save this variable and then pass it as an argument in the second method; test(first)

This will look like this:

def printfirst():
    get1 = w.get()
    get2 = e.get()
    get3 = r.get()
    get4 = t.get()
    get5 = y.get()
    first = Label(root, text= get1 + get2 + get3 + get4 + get5)
    first.pack()
    return first

def test(first):
    get1 = w.get()
    get2 = e.get()
    get3 = r.get()
    get4 = t.get()
    get5 = y.get()
    if get1 > get2:
        first.configure(text= get2 + get1 + get3 + get4 + get5)

first = printfirst()
test(first)

Python Language - NameError: name '???' is not defined, Python Language NameError: name '???' is not defined. Example#. Is raised when you tried to use a variable, method  NameError: name 'Tree' is not defined That's because the class has not been defined yet at this point. The workaround is using so called Forward Reference, i.e. wrapping a class name in a string, i.e. class Tree: def __init__(self, left: 'Tree', right: 'Tree'): self.left = left self.right = right


As the error suggests, first is not defined in def test(): You could define and initialise it as you have done in def printfirst

def test():
    get1 = w.get()
    get2 = e.get()
    get3 = r.get()
    get4 = t.get()
    get5 = y.get()
    # If this is how you want to initialise it
    first = Label(root, text= get1 + get2 + get3 + get4 + get5)
    first.pack()
    if get1 > get2:
         first.configure(text= get2 + get1 + get3 + get4 + get5)

Dealing with errors, Traceback (most recent call last): File "", line 1, in <module> print apples NameError: name 'apples' is not defined. As you can see, Python prints out an error  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more NameError: name 'plt' is not defined


You have no variable/object called first in the function test(). You need to assign it before using it. The way you do in printfirst().

Python error "NameError: name 'sr' is not defined", Other names are defined within the program (ex. variables). If Python encounters a name that it doesn't recognize, you'll probably get NameError:  With the NameError, you can study whenever and wherever you choose. We have students all over India and raising to be a global reputation as a pioneer in the field of flexible learning. Our teaching also means, if you travel often or need to relocate, you can continue to study wherever you go.


input() error, I am getting an error when I try to run this simple script: input_variable = input ("​Enter your in NameError: name 'dude' is not defined. NameError. Working to bring significant changes in online-based learning by doing extensive research for course curriculum preparation, student engagements, and


2.1: "NameError: name 'is_hungry' is not defined" yet I pass the test , 2.1: "NameError: name 'is_hungry' is not defined" yet I pass the test. My code: # Class definition class Animal(object): """Makes cute animals.""" # For initializing our  3. The error is exactly what it says. The variable event is nowhere defined. I think you should look at the tutorial again and find where the event variable is defined. I am sure pygame has some good tutorials – Uli Sotschok Oct 30 '19 at 20:08. event isn't defined. It's not a primitive in python.


input() error - NameError: name '…' is not defined, In Python 2.7, the input function is evaluated as a Python expression. But, If you simply want to read strings, then use raw_input function in  As mentioned in the introduction, a NameError will occur when the CPython interpreter does not recognize a local or global object name that has been provided in the Python source code.