├── Converter.py ├── LICENSE ├── Converter with GUI.py └── README.md /Converter.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | #Get Your API key from https://www.exchangerate-api.com 4 | API_KEY = "Place key here" 5 | BASE_URL = f"https://v6.exchangerate-api.com/v6/{API_KEY}/latest/" 6 | 7 | def get_exchange_rate(base_currency, target_currency): 8 | """Fetches exchange rate from API""" 9 | url = BASE_URL + base_currency 10 | response = requests.get(url) 11 | data = response.json() 12 | 13 | if response.status_code != 200: 14 | return None, f"Error: {data.get('error-type', 'Unknown error')}" 15 | 16 | rates = data.get("conversion_rates", {}) 17 | return rates.get(target_currency), None 18 | 19 | def convert_currency(amount, base_currency, target_currency): 20 | rate, error = get_exchange_rate(base_currency, target_currency) 21 | 22 | if error: 23 | return None, error 24 | 25 | converted_amount = amount * rate 26 | return converted_amount, None 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Collins Dada 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Converter with GUI.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import messagebox 3 | from currency_backend import convert_currency 4 | 5 | def perform_conversion(): 6 | """Handles conversion when the button is clicked""" 7 | try: 8 | amount = float(amount_entry.get()) 9 | base_currency = base_currency_entry.get().upper() 10 | target_currency = target_currency_entry.get().upper() 11 | 12 | result, error = convert_currency(amount, base_currency, target_currency) 13 | 14 | if error: 15 | messagebox.showerror("Error", error) 16 | else: 17 | result_label.config(text=f"{amount} {base_currency} = {result:.2f} {target_currency}") 18 | except ValueError: 19 | messagebox.showerror("Input Error", "Please enter a valid amount.") 20 | 21 | # GUI Setup for Converter 22 | root = tk.Tk() 23 | root.title("Currency Converter 💰") 24 | root.geometry("400x300") 25 | root.resizable(False, False) 26 | 27 | # Labels 28 | tk.Label(root, text="Amount:", font=("Arial", 12)).pack(pady=5) 29 | amount_entry = tk.Entry(root, font=("Arial", 12)) 30 | amount_entry.pack(pady=5) 31 | 32 | tk.Label(root, text="From Currency (e.g., USD):", font=("Arial", 12)).pack(pady=5) 33 | base_currency_entry = tk.Entry(root, font=("Arial", 12)) 34 | base_currency_entry.pack(pady=5) 35 | 36 | tk.Label(root, text="To Currency (e.g., EUR):", font=("Arial", 12)).pack(pady=5) 37 | target_currency_entry = tk.Entry(root, font=("Arial", 12)) 38 | target_currency_entry.pack(pady=5) 39 | 40 | #Convert Button 41 | convert_button = tk.Button(root, text="Convert", font=("Arial", 12), command=perform_conversion) 42 | convert_button.pack(pady=10) 43 | 44 | #Result Label 45 | result_label = tk.Label(root, text="", font=("Arial", 14, "bold"), fg="blue") 46 | result_label.pack(pady=10) 47 | 48 | #Start app 49 | root.mainloop() 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Currency Converter 2 | --- 3 | A **Python-based Currency Converter** with a **GUI (Tkinter) frontend** and a **separate backend module** for real-time exchange rate fetching. This project allows users to convert between different currencies using live exchange rates from the [ExchangeRate-API](https://www.exchangerate-api.com/). 4 | 5 | ## Features 6 | ✅ Real-time currency conversion using an API 7 | 8 | ✅ Simple and user-friendly GUI (Tkinter) 9 | 10 | ✅ Supports multiple currencies 11 | 12 | ✅ Error handling for invalid inputs 13 | 14 | ✅ Modular code (separate frontend and backend) 15 | 16 | --- 17 | 18 | ## 🚀 Installation & Setup 19 | 20 | ### 1️⃣ Install Dependencies 21 | Make sure you have Python installed. Then, install the required packages: 22 | ```sh 23 | pip install requests 24 | ``` 25 | 26 | ### 2️⃣ Get an API Key 27 | Sign up at [ExchangeRate-API](https://www.exchangerate-api.com/) to get a free API key. 28 | 29 | ### 3️⃣ Configure API Key 30 | Replace `your_api_key_here` in **currency_backend.py** with your actual API key: 31 | ```python 32 | API_KEY = "your_api_key_here" 33 | ``` 34 | 35 | ### 4️⃣ Run the Application 36 | Run the GUI script: 37 | ```sh 38 | python currency_converter_gui.py 39 | ``` 40 | 41 | --- 42 | 43 | ## Project Structure 44 | ``` 45 | 📁 Currency Converter Project 46 | │── currency_backend.py # Backend - Fetches exchange rates & converts currency 47 | │── currency_converter_gui.py # Frontend - Tkinter GUI for user interaction 48 | │── README.md # Project Documentation 49 | ``` 50 | 51 | --- 52 | 53 | ## Usage 54 | 1️⃣ Enter the **amount** you want to convert. 55 | 2️⃣ Specify the **base currency** (e.g., USD). 56 | 3️⃣ Specify the **target currency** (e.g., EUR). 57 | 4️⃣ Click **Convert** to see the result. 58 | 59 | --- 60 | 61 | ## Example 62 | ``` 63 | Amount: 100 64 | From Currency: USD 65 | To Currency: EUR 66 | 67 | Output: 100 USD = 92.50 EUR 68 | ``` 69 | 70 | --- 71 | 72 | ## Contribution 73 | Feel free to fork this repository and submit pull requests! Suggestions and improvements are always welcome. 😊 74 | 75 | --- 76 | 77 | ## ⚡ Author 78 | Github @ Contractor-x. 79 | 80 | 81 | --- 82 | 83 | ## 📜 License 84 | This project is open-source and available under the **MIT License**. 85 | 86 | --------------------------------------------------------------------------------