Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameError: global name 'END' is not defined

Tags:

People also ask

How do you fix NameError name is not defined?

The Python "NameError: name is not defined" occurs when we try to access a variable or function that is not defined or before it is defined. To solve the error, make sure you haven't misspelled the variable's name and access it after it has been declared.

How do I fix name errors in Python?

To specifically handle NameError in Python, you need to mention it in the except statement. In the following example code, if only the NameError is raised in the try block then an error message will be printed on the console.

Why is __ FILE __ not defined?

If you run it from a Python shell, then __file__ is not defined unless you import the code as a module.

What causes NameError?

What Is a NameError in Python? In Python, the NameError occurs when you try to use a variable, function, or module that doesn't exist or wasn't used in a valid way. Some of the common mistakes that cause this error are: Using a variable or function name that is yet to be defined.


I have found this code about scrollbar is just working fine.

from tkinter import *

master = Tk()

scrollbar = Scrollbar(master)
scrollbar.pack(side=RIGHT, fill=Y)

listbox = Listbox(master, yscrollcommand=scrollbar.set)
for i in range(10000):
    listbox.insert(END, str(i))
listbox.pack(side=LEFT, fill=BOTH)

scrollbar.config(command=listbox.yview)

mainloop()

I try to use it in my code like this:

import tkinter as tk

class interface(tk.Frame):
    def __init__(self,den):
        self.tklist() 
        #in my code, tklist is not called here. I called it here to minimize the code
        #there are stuff in here also

    def tklist(self):
        scrollbar = tk.Scrollbar(den)
        self.lst1 = tk.Listbox(den, selectmode="SINGLE", width="100", yscrollcommand=scrollbar.set)
        for i in range(1000):
            self.lst1.insert(END, str(i))
        self.lst1.pack(side=LEFT, fill=BOTH)
        scrollbar.config(command=lst1.yview)

den = tk.Tk()
den.title("Search")

inter = interface(den)

den.mainloop()

But when I ran above code, I got an error on insertion line.

NameError: global name 'END' is not defined

By the way, I tried to find documentation and a link from effbot is the closest I got but still couldn't understand what is wrong.