MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / update_balance

Function update_balance

projects/Budget-manager/main.py:88–101  ·  view source on GitHub ↗

Calculates and displays the current balance based on income and expenses.

()

Source from the content-addressed store, hash-verified

86
87# Function to calculate and display the current balance.
88def 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.

Callers 3

add_transactionFunction · 0.85
delete_transactionFunction · 0.85
main.pyFile · 0.85

Calls 1

executeMethod · 0.45

Tested by

no test coverage detected