I'm working on a project in Tkinter. Entries work perfectly fine for me, but as soon as I create an entry inside a top level window, I can neither insert any text, nor retrieve any input of the entries.
Here is a sample code:
from tkinter import *
window = Tk()
window.geometry('1000x580')
popup=Toplevel(window)
popup.geometry("300x400")
entrycolumns=Entry(popup, width=5).place(x=100,y=130)
entryrows=Entry(popup,width=5).place(x=160,y=130)
#entryrows.insert(0,"test")
#entryrows.get()
popup.mainloop()
window.mainloop()
Everything displays fine.
But as soon as I 'uncomment' and include any of those two lines for example
#entryrows.insert(0,"test")
#entryrows.get()
in order to work with the entries, I get this error message:
entryrows.insert(0,"test") AttributeError: 'NoneType' object has no attribute 'insert'
Process finished with exit code 1
It does not recognize the entries as entries anymore. Is there any way to make Entry widgets that are inside a top level window functional and accessible?
CodePudding user response:
from tkinter import *
window = Tk()
window.geometry('1000x580')
popup = Toplevel(window)
popup.geometry("300x400")
entrycolumns = Entry(popup, width=5)
entryrows = Entry(popup, width=5)
entryrows.insert(0, "test")
entryrows.get()
entrycolumns.place(x=100, y=130)
entryrows.place(x=160, y=130)
popup.mainloop()
window.mainloop()
I hope it will work for you