- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between a variable and StringVar() of Tkinter?
A variable in Tkinter is used to store the values of any data. For a Tkinter application, we can store the values in two ways −
by defining the value programmatically, or
by storing the value through user Input.
A normal variable can be used to set the value for any application whenever it is required. However, we can take the user input by creating an instance of the StringVar() object. When we specify a Tkinter variable such as textvariable, for a widget (textvariable = myvar), the widget automatically gets updated whenever the value of the variable changes. However, there might be times when we want to modify the value of the widget through the variable.
In this program, we will update the Label Widget from the StringVar(value). Whenever we want to update the value of Tkinter StringVar(), we have to change its value.
#Import the required Libraries from tkinter import * from tkinter import ttk #Create an instance of tkinter frame win = Tk() #Set the geometry of tkinter frame win.geometry("750x250") #Create a StringVar to accept user input var= StringVar(value= "Hello World!") #Create a Label label= Label(win,textvariable=var, font= ('Mistral 28 bold'), background= 'blue', foreground="white") label.pack(pady=20) win.mainloop()
Running the above code will display a label text which has the same value as defined in StringVar().
- What is the difference between the widgets of tkinter and tkinter.ttk in Python?
- Difference between tkinter and Tkinter
- What is the difference between root.destroy() and root.quit() in Tkinter(Python)?
- What is the difference between focus and focus_set methods in Tkinter?
- Difference Between Identifier and Variable
- Difference Between Local and Global Variable
- What is the difference between the country and a continent?
- What is the difference between a simile and a metaphor?
- What is the difference between a method and a function?
- What is the difference between a simulator and an emulator?
- What is the difference between = and: = assignment operators?
- What is the difference between g++ and gcc?
- What is the difference between Hinduism and Buddhism?