python-course.eu

4. Variable Classes in Tkinter

By Bernd Klein. Last modified: 16 Dec 2021.

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:

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

10 Mar to 14 Mar 2025
07 Apr to 11 Apr 2025
23 Jun to 27 Jun 2025
28 Jul to 01 Aug 2025

Efficient Data Analysis with Pandas

10 Mar to 11 Mar 2025
07 Apr to 08 Apr 2025
02 Jun to 03 Jun 2025
23 Jun to 24 Jun 2025
28 Jul to 29 Jul 2025

Python Text Processing Course

09 Apr to 11 Apr 2025
04 Jun to 06 Jun 2025

Python and Machine Learning Course

10 Mar to 14 Mar 2025
07 Apr to 11 Apr 2025
02 Jun to 06 Jun 2025
28 Jul to 01 Aug 2025

See our Python training courses

See our Machine Learning with Python training courses