Calculates and displays the current balance based on income and expenses.
()
| 86 | |
| 87 | # Function to calculate and display the current balance. |
| 88 | def update_balance(): |
| 89 | """ |
| 90 | Calculates and displays the current balance based on income and expenses. |
| 91 | """ |
| 92 | c.execute("SELECT SUM(amount) FROM transactions") |
| 93 | total_income = c.fetchone()[0] |
| 94 | if total_income is None: |
| 95 | total_income = 0.0 |
| 96 | c.execute("SELECT SUM(amount) FROM transactions WHERE amount < 0") |
| 97 | total_expense = c.fetchone()[0] |
| 98 | if total_expense is None: |
| 99 | total_expense = 0.0 |
| 100 | balance = total_income - total_expense |
| 101 | balance_label.config(text=f"Current Balance: ${balance:.2f}") |
| 102 | |
| 103 | |
| 104 | # Create the main window. |
no test coverage detected