How to Update And Delete Label Using Button


The Label is a type of widget which is used to provide a single-line caption. It can be used as a caption for other widgets. Tkinter Label widget is used to display a text or image on the screen.  A label can only display text in a single font. The text can span multiple lines. It is Used to Specify container box where we can place the text or images others. 

Syntax:  lbl = Label(root, options)
           root: It Represent Parent Window.
          options: used as key value separated by Commas. 

Example:


from tkinter import *

root =Tk()
root.title(
"Delete Label Example")
root.geometry("800x400+450+86")
root.config(bg="#FF7D40")


def update_text():
lbl.configure(text="This is Update Label text")


def on_click():
lbl.after(1000
, lbl.destroy())
#Label Will Destroyed after 1000 Milisecond

lbl = Label(root,text="Deleting Label", font=("Times new Roman", 30, "bold italic"),)
lbl.pack(pady=5)


btn1 = Button(root, text="Update",width=15,bg="#7FFFD4",
font=("Times new Roman", 20, "bold italic"),command=update_text)
btn1.pack(pady=10)


btn2 = Button(root, text="Delete",width=15,bg="#7FFFD4",
font=("Times new Roman", 20, "bold italic"),command=on_click)
btn2.pack(pady=10
)


root.mainloop()


Write Down Code Your Code Editor. To show Your Output. If Use Pycharm Press Shift+F10 and Show Your Output.


Enjoy.......

Post a Comment

Previous Post Next Post