Reputation: 3
Trying to delete the the entry widget with a button but keep getting the error
AttributeError: 'object' object has no attribute 'delete'
I shortened my code to:
from tkinter import *
e = object()
def getname():
global name
e = Entry(root, textvariable=name)
e.pack()
e.focus_set()
b = Button(root, text = "Get", width = 10, command = callback)
b.pack()
b2 = Button(root, text = "Delete", width = 10, command = delete_entry)
b2.pack()
def callback():
username = name.get()
print(username)
def delete_entry():
e.delete(0, "end")
root = Tk()
name = StringVar()
getname()
root.mainloop()
Thanks for your time
Upvotes: 0
Views: 1005
Reputation: 64
You can use this code ( which delete the Entry box totally):
def delete_entry():
e.destroy()
Or do you only want to delete the text within the Entry widget? Tell me and I will update my answer.
Upvotes: 1