Home > front end >  Why is my Placeholder not showing on my Tkinter Entry?
Why is my Placeholder not showing on my Tkinter Entry?

Time:01-06

I am working on an Entry, or Input if you please, in Python using a Library called tkinter

This is the code I have used:

entryvar = Entry(name).pack()
entryvar.insert(0,'Enter')

But when I run the code, I get the following error:

AttributeError: 'NoneType' object has no attribute 'insert'

I am not sure why this is happening as i carefully followed a tutorial on this.

I have tried switching the single inverted commas to double inverted commas and then back, but that didn't work. If you have any suggestions, It would help. Thanks!

CodePudding user response:

You are getting this error because you wrote entryvar = Entry(name).pack(). . .pack() returns as None so you should write:

entryvar = Entry(name)
entryvar.pack()
entryvar.insert(0,'Enter')

CodePudding user response:

The geometry manager methods (pack, place, and grid) all return None, so entryvar = Entry(name).pack() evaluates to None! Always declare your widgets, then pack() them separately for this reason.

Do this instead:

entryvar = Entry(name)
entryvar.pack()
entryvar.insert(0,'Enter')
  • Related