Skip to content
Romain edited this page Jun 22, 2022 · 5 revisions

Control variable properties and their usage

Some interactive tkinter widgets have properties named variable or textvarible. Those properties can contain control variables, objects used to control the value behind the widget.

To define a variable, just put the variable's name in the property editor. Use the combo box to specify the type: StringVar, IntVar, DoubleVar or BooleanVar; StringVar is the default. See the tkinter documentation about how a widget manages each type.

You can link a "tkvariable" to a slider or entry widget and then programmatically access the changing value. These variables will be uninitialized until the user first operates the control.

In code, you can retrieve a reference of the tkinter variable using the builder method get_variable(name)


An example with a set of radio buttons.

controlvariables_001

controlvariables_002

controlvariables_003

controlvariables_004

Add the following line to the generated Python code.

print('current value is ' , self.builder.get_variable('radiovar').get())

When you pull the slider back and forth with the mouse, it will print different numbers.

Interface file: controlvariables.ui

Full example code: controlvariables.py

Clone this wiki locally