Search code examples
pythonuser-interfacetkinternameerrortkinter-entry

Python 3 Tkinter: NameError with Entry widget: name 'Entry' is not defined


I am writing a GUI on Python 3 using Tkinter, but every time I use Entry(), I get a name error.

I tried a more simpler version of the code, (which is written below), but it still caused a NameError:

import tkinter
top = tkinter.Tk()

e = Entry(top)
e.pack()

top.mainloop()

This is the error I get:

Traceback (most recent call last):
  File "/home/pi/gui.py", line 4, in <module>
    e = Entry()
NameError: name 'Entry' is not defined

I only recently started coding again, so the answer is probably something extremely simple that I didn't realise was wrong with the code, but thanks for any answers.


Solution

  • You didn't import it. Change your code to:

    e = tkinter.Entry(top)
    

    Or import it explicitly:

    from tkinter import Entry