Update Label text using variable

You can Update Your Label using var that means Stringvar().

Example:

from tkinter import *                               #import Library

window = Tk()                                         #create an Instanse(create root window)
window.title("String Example")                 # Set  Title
window.geometry("800x350+450+86")  #Width x Height+ X Position+ YPosition
window.config(bg="#ADFF2F")             # Set root background color

var_2=StringVar()

label1 = Label(window, font=("helvetica", 20,"bold"),borderwidth=20,relief="solid")
label2 = Label(window, font=("helvetica", 20,"bold"),borderwidth=20, textvariable=var_2,                            relief="raised")

label1.pack(pady=20)
label2.pack(pady=20)

label1["text"]="This is First Label"
var_2.set("I Am Second Label")

window.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