I need to clear a Entry widget in tkinter after press a button

Emerson

I have a code that creates 10 entries using a for loop, which saves the result in a list so I can use get, but I have another button and I need to delete what is written in the 10 entries, how do I do that?

    for i in range(10):
        entry = Entry(self.lf_mid)
        entry.place(relwidth=0.6, relheight=1/10, relx=0.35, rely=i/10)
        lista_entrys.append(entry)
    
    #this don't work
    bt = Button(self.lf_bot, text='clear', command=entry.delete(0, 'end'))
    bt.pack(side='left', expand=1)

I appreciate if you can help me <3

InhirCode

make a widget dictionary that you add to every time you create a widget. Then wherever you want to access the widget, for example if you want to destroy it or change its configuration attributes, you do this through the dictionary.

Skeleton of the idea:

import tkinter as tk
widgetdict = {}
def maketk():
    root = tk.Tk()
    entry = tk.Entry()
    widgetdict['entry'] = entry
    root.mainloop()

maketk()
widgetdict['entry']['bg'] = '#fff'
widgetdict['entry'].destroy()

What goes into the dictionary is the pointer/address of the entry. So long as you haven't already destroyed the widget somewhere else then you have access.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why is my Tkinter label not showing up after I press a button?

How to change the plot color after a button press in matplotlib/tkinter?

Errors when trying to clear Tkinter Entry Widget

Tkinter - I can't disable the button widget

how can i make a button that when pressed it shows the name of the product to a Text widget without using an Entry widget in Tkinter

How to delete an entry when I press a Button in Python Tkinter in a class

Need to press key twice after exception - Python tkinter

Widget id not updated in configuration activity after home button press

Passing parameters to a dynamically created Button from an Entry widget in Tkinter

Need this to work with a button press

Tkinter clear a message widget

Event callback after a Tkinter Entry widget

Need help ignoring button press. Tkinter

Tkinter : I need to stop generating this "main" function called "pyrotechnik" when i press any button

tkinter update interface after button press

TKinter - Clear text widget

(Tkinter) How to get entry button to appear after button is clicked?

Countdown timer's speed increases as I press start and pause button one after another for few times in tkinter

validation of tkinter entry widget

Clear form's TextInput when i press connection button

uneditable entry box(widget) in tkinter after using in if-condition

Tkinter Entry widget insertwidth

Make the button enabled when text is entered in Entry widget on Tkinter

Tkinter entry widget execution

Can I change the menubar text after press a button? (Python, tkinter)

hint entry widget tkinter

How do I delete text when I press a button? (tkinter)

How would I get multiple Inputs from entry on a button press, Tkinter?

How do I destroy widget on button press and open MainWindow?

TOP Ranking

HotTag

Archive