Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feature to calcuate price in INR. #71

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Shopping-list.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from tkinter import messagebox, ttk
import json
import os
from forex_python.converter import CurrencyRates

# Global variables
shopping_list = {}
Expand All @@ -14,6 +15,7 @@
filename = "shopping_list.json"
categories = ["Grocery", "Stationery", "Electronics", "Household", "Clothing", "Other", "All"]


# Function to load shopping list from a JSON file
def load_list():
global shopping_list
Expand Down Expand Up @@ -43,6 +45,7 @@ def update_button_states():
button_display.config(state=tk.DISABLED if is_empty else tk.NORMAL)
button_search.config(state=tk.DISABLED if is_empty else tk.NORMAL)
button_calculate.config(state=tk.DISABLED if is_empty else tk.NORMAL)
button_calculate_in_INR.config(state=tk.DISABLED if is_empty else tk.NORMAL)
button_clear.config(state=tk.DISABLED if is_empty else tk.NORMAL)

# Function to add an item to the shopping list
Expand Down Expand Up @@ -120,8 +123,18 @@ def clear_list():
# Function to calculate the total cost of all items
def calculate_total():
total = sum(amount * price for amount, price, _ in shopping_list.values())
print(total)
messagebox.showinfo("Total Cost", f"Total cost of items in the shopping list: ${total:.2f}")


def calculate_total_in_inr():
total = sum(amount * price for amount, price, _ in shopping_list.values())
# cr=CurrencyRates()
total_in_inr=total*80

messagebox.showinfo("Total Cost", f"Total cost of items in the shopping list: Rs {total_in_inr:.2f}")


# Function to search for an item in the shopping list
def search_item():
global entry_item
Expand Down Expand Up @@ -150,7 +163,7 @@ def clear_entries():
# Main function to set up the UI
def main():
global entry_item, entry_amount, entry_price, listbox, combobox_category, combobox_filter
global button_edit, button_remove, button_display, button_search, button_calculate, button_clear
global button_edit, button_remove, button_display, button_search, button_calculate,button_calculate_in_INR, button_clear

load_list() # Load the shopping list at startup
root = tk.Tk()
Expand Down Expand Up @@ -221,6 +234,9 @@ def main():
button_calculate = tk.Button(frame, text="Calculate Total Cost", font=("Arial", 12), bg="#FF7F50", fg="black", command=calculate_total)
button_calculate.grid(row=7, column=1, padx=5, pady=5, sticky="we")

button_calculate_in_INR = tk.Button(frame, text="Calculate Total Cost in INR", font=("Arial", 12), bg="#FF7F50", fg="black", command=calculate_total_in_inr)
button_calculate_in_INR.grid(row=9, column=0, padx=5, pady=5, sticky="we")

button_clear = tk.Button(frame, text="Clear List", font=("Arial", 12), bg="#FF7F50", fg="black", command=clear_list)
button_clear.grid(row=8, column=0, padx=5, pady=5, columnspan=2, sticky="we")

Expand Down