Home > Back-end >  How to make a clear function in python tkinter?
How to make a clear function in python tkinter?

Time:08-27

I want to add a clear button in tkinter which clears the text I have entered already and the output. How can I do that? Here is my code which gets input and provide output using Label.

from tkinter import *
root = Tk()

def myFunction():
    k = myInput.get()
    labl = Label(root,text=k)
    labl.pack()

myInput = Entry(root,width=50, bg="#d2ebd5",borderwidth=5)
myInput.pack()

myButton = Button(root,text="Click me!",command=myFunction)
myButton.pack()

root.mainloop()

CodePudding user response:

Use myInput.set("") to clear Entry var, move labl from function to main level, create another function to clear Entry var and labl text and button to run it.

CodePudding user response:

This should help you

delte entry field

  • Related