import tkinter as tk from tkinter import messagebox # Fixed exchange rates exchange_rates = {'NZD': {'USD': 0.68, 'CAD': 0.86}, 'USD': {'NZD': 1.47, 'CAD': 1.27}, 'CAD': {'NZD': 1.17, 'USD': 0.79}} # Default button colors DEFAULT_BUTTON_COLOR = "#4CAF50" # Green DEFAULT_HELP_BUTTON_COLOR = "#FFD700" # Gold def convert_currency(): from_currency = from_currency_var.get() to_currency = to_currency_var.get() amount = float(amount_entry.get()) if from_currency == to_currency: messagebox.showerror("Error", "Please select different currencies.") return converted_amount = amount * exchange_rates[from_currency][to_currency] result_label.config(text=f"{amount} {from_currency} equals {converted_amount:.2f} {to_currency}") def display_help(): help_text = ("Welcome to the Currency Converter!\n\n" "1. Select the 'From Currency' and 'To Currency' from the dropdown menus.\n" "2. Enter the amount you want to convert in the 'Amount' field.\n" "3. Click the 'Convert' button to see the conversion result.\n\n" "Thank you for using our Currency Converter!") messagebox.showinfo("Help", help_text) # GUI setup root = tk.Tk() root.title("Currency Converter") from_currency_var = tk.StringVar(root) from_currency_var.set("NZD") # default value to_currency_var = tk.StringVar(root) to_currency_var.set("USD") # default value tk.Label(root, text="From Currency:").grid(row=0, column=0, padx=5, pady=5) from_currency_menu = tk.OptionMenu(root, from_currency_var, *exchange_rates.keys()) from_currency_menu.grid(row=0, column=1, padx=5, pady=5) tk.Label(root, text="To Currency:").grid(row=1, column=0, padx=5, pady=5) to_currency_menu = tk.OptionMenu(root, to_currency_var, *exchange_rates.keys()) to_currency_menu.grid(row=1, column=1, padx=5, pady=5) tk.Label(root, text="Amount:").grid(row=2, column=0, padx=5, pady=5) amount_entry = tk.Entry(root) amount_entry.grid(row=2, column=1, padx=5, pady=5) convert_button = tk.Button(root, text="Convert", command=convert_currency) convert_button.grid(row=3, column=0, columnspan=2, padx=5, pady=5) convert_button_color = DEFAULT_BUTTON_COLOR # Set default color convert_button.config(bg=convert_button_color) result_label = tk.Label(root, text="") result_label.grid(row=4, column=0, columnspan=2, padx=5, pady=5) help_button = tk.Button(root, text="Help", command=display_help) help_button.grid(row=5, column=0, columnspan=2, padx=5, pady=5) help_button_color = DEFAULT_HELP_BUTTON_COLOR # Set default color help_button.config(bg=help_button_color) root.mainloop()