Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 253
Bill Reason Avatar asked Sep 18 '26 12:09

Bill Reason


1 Answers

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

e = tkinter.Entry(top)

Or import it explicitly:

from tkinter import Entry
like image 90
Danil Speransky Avatar answered Sep 21 '26 00:09

Danil Speransky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!