GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • python-course.eu
  • Python Tutorial
  • OOP
  • Advanced
  • Annotations
  • Applications
  • Numerical Programming
  • Machine Learning
  • Tkinter
  • Projects
  • About
  • Instructor-led training courses by Bernd Klein
  • Labels in Tkinter
  • Message widget in Tkinter

This view

  • Original page
  • New address

GeezerVison is showing python-course.eu — 4. Variable Classes in Tkinter | Tkinter | python-course.eu

4. Variable Classes in Tkinter

By Bernd Klein. Last modified: 16 Dec 2021.

On this page ➤

Variable Classes

Some widgets (like text entry widgets, radio buttons and so on) can be connected directly to application variables by using special options: variable, textvariable, onvalue, offvalue, and value. This connection works both ways: if the variable changes for any reason, the widget it's connected to will be updated to reflect the new value. These Tkinter control variables are used like regular Python variables to keep certain values.

It's not possible to hand over a regular Python variable to a widget through a variable or textvariable option. The only kinds of variables for which this works are variables that are subclassed from a class called Variable, defined in the Tkinter module. They are declared like this:

  • x = StringVar() # Holds a string; default value ""
  • x = IntVar() # Holds an integer; default value 0
  • x = DoubleVar() # Holds a float; default value 0.0
  • x = BooleanVar() # Holds a boolean, returns 0 for False and 1 for True

To read the current value of such a variable, call the method get(). The value of such a variable can be changed with the set() method.

Live Python training

instructor-led training course

Enjoying this page? We offer live Python training courses covering the content of this site.

Upcoming online Courses

Python Intensive Course

Efficient Data Analysis with Pandas

Python Text Processing Course

Python and Machine Learning Course

See our Python training courses

See our Machine Learning with Python training courses

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.