Skip to content

main_tab

Main calculator tab builder.

build_main_tab(app, parent)

Build the calculator tab inputs and result panels.

Parameters:

Name Type Description Default
app RefinanceCalculatorApp

Application instance that owns the tab data.

required
parent Frame

Frame that hosts the calculator elements.

required
Source code in src/refi_calculator/gui/builders/main_tab.py
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
def build_main_tab(
    app: RefinanceCalculatorApp,
    parent: ttk.Frame,
) -> None:
    """Build the calculator tab inputs and result panels.

    Args:
        app: Application instance that owns the tab data.
        parent: Frame that hosts the calculator elements.
    """
    input_frame = ttk.Frame(parent)
    input_frame.pack(fill=tk.X, pady=(0, 10))

    current_frame = ttk.LabelFrame(input_frame, text="Current Loan", padding=10)
    current_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, padx=(0, 5))

    add_input(current_frame, "Balance ($):", app.current_balance, 0, app._calculate)
    add_input(current_frame, "Rate (%):", app.current_rate, 1, app._calculate)
    add_input(current_frame, "Years Remaining:", app.current_remaining, 2, app._calculate)

    new_frame = ttk.LabelFrame(input_frame, text="New Loan", padding=10)
    new_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=True, padx=(5, 0))

    add_input(new_frame, "Rate (%):", app.new_rate, 0, app._calculate)
    add_input(new_frame, "Term (years):", app.new_term, 1, app._calculate)
    add_input(new_frame, "Closing Costs ($):", app.closing_costs, 2, app._calculate)
    add_input(new_frame, "Cash Out ($):", app.cash_out, 3, app._calculate)
    add_input(new_frame, "Opportunity Rate (%):", app.opportunity_rate, 4, app._calculate)
    add_input(new_frame, "Marginal Tax Rate (%):", app.marginal_tax_rate, 5, app._calculate)

    maintain_frame = ttk.Frame(new_frame)
    maintain_frame.grid(row=6, column=0, columnspan=2, sticky=tk.W, pady=(8, 0))
    ttk.Checkbutton(
        maintain_frame,
        text="Maintain current payment (extra → principal)",
        variable=app.maintain_payment,
        command=app._calculate,
    ).pack(anchor=tk.W)

    btn_frame = ttk.Frame(parent)
    btn_frame.pack(pady=8)
    ttk.Button(btn_frame, text="Calculate", command=app._calculate).pack(side=tk.LEFT, padx=5)
    ttk.Button(btn_frame, text="Export CSV", command=app._export_csv).pack(
        side=tk.LEFT,
        padx=5,
    )

    results_frame = ttk.LabelFrame(parent, text="Analysis Results", padding=12)
    results_frame.pack(fill=tk.BOTH, expand=True)

    style = ttk.Style()
    style.configure("Header.TLabel", font=("Segoe UI", 9, "bold"))
    style.configure("Result.TLabel", font=("Segoe UI", 10))
    style.configure("Big.TLabel", font=("Segoe UI", 13, "bold"))

    app.pay_frame = ttk.Frame(results_frame)
    app.pay_frame.pack(fill=tk.X, pady=(0, 8))
    app.current_pmt_label = result_block(app.pay_frame, "Current Payment", 0)
    app.new_pmt_label = result_block(app.pay_frame, "New Payment", 1)
    app.savings_label = result_block(app.pay_frame, "Monthly Δ", 2)

    app.balance_frame = ttk.Frame(results_frame)
    app.balance_frame.pack(fill=tk.X, pady=(0, 8))
    app.new_balance_label = result_block(app.balance_frame, "New Loan Balance", 0)
    app.cash_out_label = result_block(app.balance_frame, "Cash Out", 1)
    result_block(app.balance_frame, "", 2)
    app.balance_frame.pack_forget()

    ttk.Separator(results_frame, orient=tk.HORIZONTAL).pack(fill=tk.X, pady=6)

    be_frame = ttk.Frame(results_frame)
    be_frame.pack(fill=tk.X, pady=(0, 8))
    app.simple_be_label = result_block(be_frame, "Simple Breakeven", 0)
    app.npv_be_label = result_block(be_frame, "NPV Breakeven", 1)

    ttk.Separator(results_frame, orient=tk.HORIZONTAL).pack(fill=tk.X, pady=6)

    int_frame = ttk.Frame(results_frame)
    int_frame.pack(fill=tk.X, pady=(0, 8))
    app.curr_int_label = result_block(int_frame, "Current Total Interest", 0)
    app.new_int_label = result_block(int_frame, "New Total Interest", 1)
    app.int_delta_label = result_block(int_frame, "Interest Δ", 2)

    ttk.Separator(results_frame, orient=tk.HORIZONTAL).pack(fill=tk.X, pady=6)

    app.tax_section_label = ttk.Label(
        results_frame,
        text="After-Tax Analysis (0% marginal rate)",
        style="Header.TLabel",
    )
    app.tax_section_label.pack(anchor=tk.W, pady=(0, 6))

    tax_pay_frame = ttk.Frame(results_frame)
    tax_pay_frame.pack(fill=tk.X, pady=(0, 8))
    app.at_current_pmt_label = result_block(tax_pay_frame, "Current (After-Tax)", 0)
    app.at_new_pmt_label = result_block(tax_pay_frame, "New (After-Tax)", 1)
    app.at_savings_label = result_block(tax_pay_frame, "Monthly Δ (A-T)", 2)

    tax_be_frame = ttk.Frame(results_frame)
    tax_be_frame.pack(fill=tk.X, pady=(0, 8))
    app.at_simple_be_label = result_block(tax_be_frame, "Simple BE (A-T)", 0)
    app.at_npv_be_label = result_block(tax_be_frame, "NPV BE (A-T)", 1)
    app.at_int_delta_label = result_block(tax_be_frame, "Interest Δ (A-T)", 2)

    ttk.Separator(results_frame, orient=tk.HORIZONTAL).pack(fill=tk.X, pady=6)

    app.accel_section_frame = ttk.Frame(results_frame)
    app.accel_section_label = ttk.Label(
        app.accel_section_frame,
        text="Accelerated Payoff (Maintain Payment)",
        style="Header.TLabel",
    )
    app.accel_section_label.pack(anchor=tk.W, pady=(0, 6))

    accel_row1 = ttk.Frame(app.accel_section_frame)
    accel_row1.pack(fill=tk.X, pady=(0, 8))
    app.accel_months_label = result_block(accel_row1, "Payoff Time", 0)
    app.accel_time_saved_label = result_block(accel_row1, "Time Saved", 1)
    app.accel_interest_saved_label = result_block(accel_row1, "Interest Saved", 2)

    ttk.Separator(app.accel_section_frame, orient=tk.HORIZONTAL).pack(fill=tk.X, pady=6)

    npv_cost_frame = ttk.Frame(results_frame)
    npv_cost_frame.pack(fill=tk.X, pady=(0, 8))

    ttk.Label(results_frame, text="Total Cost NPV Analysis", style="Header.TLabel").pack(
        anchor=tk.W,
        pady=(0, 6),
    )

    npv_cost_row = ttk.Frame(results_frame)
    npv_cost_row.pack(fill=tk.X, pady=(0, 8))
    app.current_cost_npv_label = result_block(npv_cost_row, "Current Loan NPV", 0)
    app.new_cost_npv_label = result_block(npv_cost_row, "New Loan NPV", 1)
    app.cost_npv_advantage_label = result_block(npv_cost_row, "NPV Advantage", 2)

    ttk.Separator(results_frame, orient=tk.HORIZONTAL).pack(fill=tk.X, pady=6)

    npv_frame = ttk.Frame(results_frame)
    npv_frame.pack(fill=tk.X)
    app.npv_title_label = ttk.Label(
        npv_frame,
        text="5-Year NPV of Refinancing",
        style="Header.TLabel",
    )
    app.npv_title_label.pack()
    app.five_yr_npv_label = ttk.Label(npv_frame, text="$0", style="Big.TLabel")
    app.five_yr_npv_label.pack(pady=3)