I\'m trying to clear the Entry widget after the user presses a button using Tkinter.
I tried using ent.delete(0, END), but I got an error
if you add the print code to check the type of real, you will see that real is a string, not an Entry so there is no delete attribute.
def res(real, secret):
print(type(real))
if secret==eval(real):
showinfo(message='that is right!')
real.delete(0, END)
>> output:
secret = randrange(1,100)
print(secret)
def res(real, secret):
if secret==eval(real):
showinfo(message='that is right!')
ent.delete(0, END) # we call the entry an delete its content
def guess():
ge = Tk()
ge.title('guessing game')
Label(ge, text="what is your guess:").pack(side=TOP)
global ent # Globalize ent to use it in other function
ent = Entry(ge)
ent.pack(side=TOP)
btn=Button(ge, text="Enter", command=lambda: res(ent.get(),secret))
btn.pack(side=LEFT)
ge.mainloop()
It should work.