import tkinter as tk
from tkinter import ttk, messagebox

exchange_rates = {
    "USD": 1.0,        
    "EUR": 0.92,
    "INR": 87.10,
    "GBP": 0.78,
    "JPY": 146.55
}

def convert_currency():
    try:
        amount = float(amount_entry.get())
        from_currency = from_combo.get()
        to_currency = to_combo.get()
        
        if from_currency and to_currency:
            usd_amount = amount / exchange_rates[from_currency]
            converted = usd_amount * exchange_rates[to_currency]
            result_label.config(text=f"{amount} {from_currency} = {converted:.2f} {to_currency}")
        else:
            messagebox.showerror("Error", "Please select currencies")
    except ValueError:
        messagebox.showerror("Error", "Enter a valid amount")

root = tk.Tk()
root.title("Currency Converter")
root.geometry("400x250")

tk.Label(root, text="Amount:", font=("Arial", 12)).pack(pady=5)
amount_entry = tk.Entry(root, font=("Arial", 12))
amount_entry.pack(pady=5)

tk.Label(root, text="From Currency:", font=("Arial", 12)).pack()
from_combo = ttk.Combobox(root, values=list(exchange_rates.keys()), font=("Arial", 12))
from_combo.pack()

tk.Label(root, text="To Currency:", font=("Arial", 12)).pack()
to_combo = ttk.Combobox(root, values=list(exchange_rates.keys()), font=("Arial", 12))
to_combo.pack()


tk.Button(root, text="Convert", command=convert_currency, font=("Arial", 12), bg="lightblue").pack(pady=10)

result_label = tk.Label(root, text="", font=("Arial", 14, "bold"))
result_label.pack(pady=10)

root.mainloop()
