Skip to content

Variables

Lasha Kandelaki edited this page May 7, 2026 · 3 revisions

Variables

Shared values widgets can bind to. Change one variable, every bound widget updates live. Two scopes: global (project-wide) and local (per form).

Open the Data window

F11 or View → Data.

The window has three tabs — variables share the surface with Object References since v1.10.8:

Tab Scope Visible to
Global Whole project Every widget in every form
Local: <form-name> The active form only Widgets inside that form
Object References Widget pointers See Object References

The Local tab follows the active document — switch forms and the tab relabels.

Types

Type Tk runtime Use for
str tk.StringVar text labels, entries, dropdown values
int tk.IntVar counts, indices
float tk.DoubleVar sliders, progress
bool tk.BooleanVar switches, checkboxes
color tk.StringVar (hex) shared accent / theme colors across widgets

Add / Rename / Delete

Toolbar buttons in the Variables window. Renaming is safe — bindings reference the variable's UUID, not its name.

Bind a widget property

In the Properties panel, click the in a row's left gutter to bind that property to a variable. Bound rows show + an orange tint; the on the right unbinds.

The diamond's color tells you the scope:

  • 🔵 Blue ◆ — bound to a global variable
  • 🟠 Orange ◆ — bound to a local variable

Double-click a bound row to jump straight to that variable in the Data window.

Updates propagate live in two directions:

  • Tk-wired bindings (e.g. textvariable / variable) — typing into one Entry mirrors instantly into every Label / Switch / Slider sharing the variable.
  • Cosmetic bindings (e.g. fg_color, where Tk has no *Var hook) — editing the variable's default value re-applies through widget.configure(...) on every bound widget without rebuilding the canvas.

Cross-form moves

Dragging or pasting a widget from one form to another can break local-variable bindings (the target form doesn't own those vars). When that happens, a Reparent Variables dialog opens with two choices:

Source Target
Keep the originals Duplicate them in the target form (or reuse a same-name match)
Delete the originals Unbind the moved widgets

Cancel aborts the whole move.

Export

Globals declare on the main window class as self.var_X; Toplevels read them as self.master.var_X. Locals declare on their owning class. Either way, every bound property becomes a shared tk.Variable — no extra wiring.


See alsoProperties Panel · Object References · Exporting Code · Keyboard Shortcuts

Clone this wiki locally