If You Want to Update label using function you must follow below Procedure. Here I Will Show How to Update Label Text Using function.

Lets Start ..............


from tkinter import *

my_window = Tk()
my_window.title("Update Label text Using Function")
my_window.geometry("800x350+450+86")
my_window.config(bg="#4B0082")

var_1 = StringVar()
var_1.set("I Want To Learn........")


def web():
var_1.set("You Must learn PHP & Mysql")

def python():
var_1.set("You Must Learn Python")

btn_1 = Button(my_window,text="I love Web Development"font=("Times",20,"bold"),
              (command=web)
btn_2 = Button(my_window,text="I love Data Science",font=("Times",20,"bold")
              command=python)

btn_1.pack(pady=10)
btn_2.pack(pady=10)


lbl1 = Label(my_window,font=("Times",30, "bold"),textvariable=var_1)
lbl1.pack(pady=10)

my_window.mainloop()

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



Enjoy.........

If Any Problem Plz comment Below

Post a Comment

Previous Post Next Post