TextVariable in Tkinter 


A variable defined using StringVar() holds a string data where we can set text value and can retrieve it.These variables also contain getter and setter methods to access and change their values.The widget will automatically get updated with the new value whenever the value of the StringVar() variable changes.

Example: 

from tkinter import *

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

def  click():
      var.set("I am Tempurary Label")

def  RESET():
       var.set("I am Stable Label")

var=StringVar()
var.set("I am Stable Label ")

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

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

btn2 = Button(root, text="RESET",width=15,bg="#76EE00",
                         font=("Times new Roman", 20, "bold italic"),command=RESET)
btn2.pack(pady=10)

btn3 =Button(root, text="Quit",width=15,bg="#EE1289",
font=("Times new Roman", 20, "bold italic"),command=root.quit)
btn3.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

أحدث أقدم