Skip to content

helpers

Common helpers for building UI tabs.

add_input(parent, label, var, row, on_change)

Add a labeled entry bound to the provided StringVar.

Parameters:

Name Type Description Default
parent Misc

Parent frame hosting the entry row.

required
label str

Text displayed next to the entry.

required
var StringVar

StringVar that stores the entry value.

required
row int

Grid row for the label/entry pair.

required
on_change Callable[[], None]

Callback invoked when the value changes.

required
Source code in src/refi_calculator/gui/builders/helpers.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def add_input(
    parent: tk.Misc,
    label: str,
    var: tk.StringVar,
    row: int,
    on_change: Callable[[], None],
) -> None:
    """Add a labeled entry bound to the provided StringVar.

    Args:
        parent: Parent frame hosting the entry row.
        label: Text displayed next to the entry.
        var: StringVar that stores the entry value.
        row: Grid row for the label/entry pair.
        on_change: Callback invoked when the value changes.
    """
    ttk.Label(parent, text=label).grid(row=row, column=0, sticky=tk.W, pady=3)
    entry = ttk.Entry(parent, textvariable=var, width=14)
    entry.grid(row=row, column=1, sticky=tk.E, pady=3, padx=(10, 0))
    entry.bind("<Return>", lambda e: on_change())
    entry.bind("<FocusOut>", lambda e: on_change())

add_option(parent, label, var, row, tooltip)

Add a labeled option input with descriptive tooltip.

Parameters:

Name Type Description Default
parent Misc

Parent frame used for the input row.

required
label str

Label text describing the option.

required
var StringVar

StringVar associated with the option entry.

required
row int

Row index inside the grid layout.

required
tooltip str

Supplemental explanation shown alongside input.

required
Source code in src/refi_calculator/gui/builders/helpers.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def add_option(
    parent: tk.Misc,
    label: str,
    var: tk.StringVar,
    row: int,
    tooltip: str,
) -> None:
    """Add a labeled option input with descriptive tooltip.

    Args:
        parent: Parent frame used for the input row.
        label: Label text describing the option.
        var: StringVar associated with the option entry.
        row: Row index inside the grid layout.
        tooltip: Supplemental explanation shown alongside input.
    """
    ttk.Label(parent, text=label).grid(row=row, column=0, sticky=tk.W, pady=6)
    entry = ttk.Entry(parent, textvariable=var, width=10)
    entry.grid(row=row, column=1, sticky=tk.W, pady=6, padx=(10, 15))
    ttk.Label(parent, text=tooltip, font=("Segoe UI", 8), foreground="#666").grid(
        row=row,
        column=2,
        sticky=tk.W,
    )

result_block(parent, title, col)

Create a title + value display block within a row.

Parameters:

Name Type Description Default
parent Frame

Parent frame that hosts the result block.

required
title str

Title text displayed above the value.

required
col int

Column index used for layout (unused but maintained for parity).

required

Returns:

Type Description
Label

The label that shows the numeric value.

Source code in src/refi_calculator/gui/builders/helpers.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def result_block(
    parent: ttk.Frame,
    title: str,
    col: int,
) -> ttk.Label:
    """Create a title + value display block within a row.

    Args:
        parent: Parent frame that hosts the result block.
        title: Title text displayed above the value.
        col: Column index used for layout (unused but maintained for parity).

    Returns:
        The label that shows the numeric value.
    """
    frame = ttk.Frame(parent)
    frame.pack(side=tk.LEFT, expand=True, fill=tk.X)
    ttk.Label(frame, text=title, style="Header.TLabel").pack()
    label = ttk.Label(frame, text="—", style="Result.TLabel")
    label.pack(pady=2)
    return label