Skip to content

Currency Exchange Rate Calculator GUI

Abstract

Create a professional currency exchange rate calculator with a graphical interface that fetches real-time exchange rates from an API and converts between multiple currencies. This project demonstrates GUI development, API integration, and financial data processing.

Prerequisites

  • Python 3.6 or above
  • Text Editor or IDE
  • Basic understanding of Python syntax
  • Knowledge of Tkinter for GUI development
  • Familiarity with HTTP requests and APIs
  • Understanding of JSON data processing

Getting Started

Create a new project

  1. Create a new project folder and name it currencyExchangeCalculatorcurrencyExchangeCalculator.
  2. Create a new file and name it currencyexchnageratecalculator.pycurrencyexchnageratecalculator.py.
  3. Open the project folder in your favorite text editor or IDE.
  4. Copy the code below and paste it into your currencyexchnageratecalculator.pycurrencyexchnageratecalculator.py file.

Install required dependencies

  1. Install requests library for API calls:
pip install requests
pip install requests

Write the code

  1. Add the following code to your currencyexchnageratecalculator.pycurrencyexchnageratecalculator.py file.
βš™οΈ Currency Exchange Rate Calculator GUI
Currency Exchange Rate Calculator GUI
# Currency Exchange Rate Calculator GUI
 
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
import requests
import json
 
# Create an instance of tkinter frame
win = Tk()
 
# Set the geometry of tkinter frame
win.geometry("700x400")
 
# Set the title of tkinter frame
win.title("Currency Exchange Rate Calculator")
 
# Disable resizing the GUI by passing in False/False
win.resizable(False, False)
 
# Create a function to convert currency
def exchange():
    # Get the amount from the amount entry box
    amount = float(amount_entry.get())
    
    # Get the currency from the currency combobox
    currency = currency_combo.get()
    
    # Get the converted currency from the converted currency combobox
    converted_currency = converted_currency_combo.get()
    
    # Create a base URL
    base_url = "https://api.exchangerate-api.com/v4/latest/"
    
    # Create a full URL
    full_url = base_url + currency
    
    # Send a request to the URL
    response = requests.get(full_url)
    
    # Convert the response to JSON format
    response_json = response.json()
    
    # Get the currency rates from the response
    rates = response_json['rates']
    
    # Get the currency rate for the converted currency
    converted_currency_rate = rates[converted_currency]
    
    # Calculate the converted currency amount
    converted_currency_amount = converted_currency_rate * amount
    
    # Round the converted currency amount to 2 decimal places
    converted_currency_amount = round(converted_currency_amount, 2)
    
    # Create a message box to display the converted currency amount
    messagebox.showinfo("Converted Currency Amount", f"{converted_currency_amount} {converted_currency}")
    
# Create a function to clear the GUI
def clear():
    # Clear the amount entry box
    amount_entry.delete(0, END)
    
    # Clear the currency combobox
    currency_combo.set("")
    
    # Clear the converted currency combobox
    converted_currency_combo.set("")
    
# Create a function to exit the GUI
def exit():
    # Exit the GUI
    win.destroy()
    
# Create a label for the amount entry box
amount_label = Label(win, text="Amount:", font=("Arial", 10, "bold"))
 
# Create a label for the currency combobox
currency_label = Label(win, text="Currency:", font=("Arial", 10, "bold"))
 
# Create a label for the converted currency combobox
converted_currency_label = Label(win, text="Converted Currency:", font=("Arial", 10, "bold"))
 
# Create a label for the amount entry box
amount_label.place(x=30, y=50)
 
# Create a label for the currency combobox
currency_label.place(x=30, y=100)
 
# Create a label for the converted currency combobox
converted_currency_label.place(x=30, y=150)
 
# Create a variable for the amount entry box
amount = StringVar()
 
# Create an entry box for the amount
amount_entry = Entry(win, textvariable=amount, font=("Arial", 10, "normal"), width=20)
 
# Create a variable for the currency combobox
currency = StringVar()
 
# Create a combobox for the currency
currency_combo = ttk.Combobox(win, textvariable=currency, font=("Arial", 10, "normal"), width=18)
 
# Create a variable for the converted currency combobox
converted_currency = StringVar()
 
# Create a combobox for the converted currency
converted_currency_combo = ttk.Combobox(win, textvariable=converted_currency, font=("Arial", 10, "normal"), width=18)
 
# Create a list of currencies
currencies = ["USD", "EUR", "GBP", "INR", "AUD", "CAD", "SGD", "CHF", "MYR", "JPY", "CNY"]
 
# Set the default value for the currency combobox
currency_combo.set("Select Currency")
 
# Set the default value for the converted currency combobox
converted_currency_combo.set("Select Converted Currency")
 
# Add the currencies to the currency combobox
currency_combo['values'] = currencies
 
# Add the currencies to the converted currency combobox
converted_currency_combo['values'] = currencies
 
# Create a button to convert currency
convert_button = Button(win, text="Convert", font=("Arial", 10, "bold"), command=exchange)
 
# Create a button to clear the GUI
clear_button = Button(win, text="Clear", font=("Arial", 10, "bold"), command=clear)
 
# Create a button to exit the GUI
exit_button = Button(win, text="Exit", font=("Arial", 10, "bold"), command=exit)
 
# Create an entry box for the amount
amount_entry.place(x=200, y=50)
 
# Create a combobox for the currency
currency_combo.place(x=200, y=100)
 
# Create a combobox for the converted currency
converted_currency_combo.place(x=200, y=150)
 
# Create a button to convert currency
convert_button.place(x=30, y=200)
 
# Create a button to clear the GUI
clear_button.place(x=130, y=200)
 
# Create a button to exit the GUI
exit_button.place(x=230, y=200)
 
# Run the tkinter event loop
win.mainloop() 
Currency Exchange Rate Calculator GUI
# Currency Exchange Rate Calculator GUI
 
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
import requests
import json
 
# Create an instance of tkinter frame
win = Tk()
 
# Set the geometry of tkinter frame
win.geometry("700x400")
 
# Set the title of tkinter frame
win.title("Currency Exchange Rate Calculator")
 
# Disable resizing the GUI by passing in False/False
win.resizable(False, False)
 
# Create a function to convert currency
def exchange():
    # Get the amount from the amount entry box
    amount = float(amount_entry.get())
    
    # Get the currency from the currency combobox
    currency = currency_combo.get()
    
    # Get the converted currency from the converted currency combobox
    converted_currency = converted_currency_combo.get()
    
    # Create a base URL
    base_url = "https://api.exchangerate-api.com/v4/latest/"
    
    # Create a full URL
    full_url = base_url + currency
    
    # Send a request to the URL
    response = requests.get(full_url)
    
    # Convert the response to JSON format
    response_json = response.json()
    
    # Get the currency rates from the response
    rates = response_json['rates']
    
    # Get the currency rate for the converted currency
    converted_currency_rate = rates[converted_currency]
    
    # Calculate the converted currency amount
    converted_currency_amount = converted_currency_rate * amount
    
    # Round the converted currency amount to 2 decimal places
    converted_currency_amount = round(converted_currency_amount, 2)
    
    # Create a message box to display the converted currency amount
    messagebox.showinfo("Converted Currency Amount", f"{converted_currency_amount} {converted_currency}")
    
# Create a function to clear the GUI
def clear():
    # Clear the amount entry box
    amount_entry.delete(0, END)
    
    # Clear the currency combobox
    currency_combo.set("")
    
    # Clear the converted currency combobox
    converted_currency_combo.set("")
    
# Create a function to exit the GUI
def exit():
    # Exit the GUI
    win.destroy()
    
# Create a label for the amount entry box
amount_label = Label(win, text="Amount:", font=("Arial", 10, "bold"))
 
# Create a label for the currency combobox
currency_label = Label(win, text="Currency:", font=("Arial", 10, "bold"))
 
# Create a label for the converted currency combobox
converted_currency_label = Label(win, text="Converted Currency:", font=("Arial", 10, "bold"))
 
# Create a label for the amount entry box
amount_label.place(x=30, y=50)
 
# Create a label for the currency combobox
currency_label.place(x=30, y=100)
 
# Create a label for the converted currency combobox
converted_currency_label.place(x=30, y=150)
 
# Create a variable for the amount entry box
amount = StringVar()
 
# Create an entry box for the amount
amount_entry = Entry(win, textvariable=amount, font=("Arial", 10, "normal"), width=20)
 
# Create a variable for the currency combobox
currency = StringVar()
 
# Create a combobox for the currency
currency_combo = ttk.Combobox(win, textvariable=currency, font=("Arial", 10, "normal"), width=18)
 
# Create a variable for the converted currency combobox
converted_currency = StringVar()
 
# Create a combobox for the converted currency
converted_currency_combo = ttk.Combobox(win, textvariable=converted_currency, font=("Arial", 10, "normal"), width=18)
 
# Create a list of currencies
currencies = ["USD", "EUR", "GBP", "INR", "AUD", "CAD", "SGD", "CHF", "MYR", "JPY", "CNY"]
 
# Set the default value for the currency combobox
currency_combo.set("Select Currency")
 
# Set the default value for the converted currency combobox
converted_currency_combo.set("Select Converted Currency")
 
# Add the currencies to the currency combobox
currency_combo['values'] = currencies
 
# Add the currencies to the converted currency combobox
converted_currency_combo['values'] = currencies
 
# Create a button to convert currency
convert_button = Button(win, text="Convert", font=("Arial", 10, "bold"), command=exchange)
 
# Create a button to clear the GUI
clear_button = Button(win, text="Clear", font=("Arial", 10, "bold"), command=clear)
 
# Create a button to exit the GUI
exit_button = Button(win, text="Exit", font=("Arial", 10, "bold"), command=exit)
 
# Create an entry box for the amount
amount_entry.place(x=200, y=50)
 
# Create a combobox for the currency
currency_combo.place(x=200, y=100)
 
# Create a combobox for the converted currency
converted_currency_combo.place(x=200, y=150)
 
# Create a button to convert currency
convert_button.place(x=30, y=200)
 
# Create a button to clear the GUI
clear_button.place(x=130, y=200)
 
# Create a button to exit the GUI
exit_button.place(x=230, y=200)
 
# Run the tkinter event loop
win.mainloop() 
  1. Save the file.
  2. Run the following command to run the application.
command
C:\Users\username\Documents\currencyExchangeCalculator> python currencyexchnageratecalculator.py
[Currency Exchange Calculator GUI Opens]
- Enter amount to convert
- Select base currency from dropdown
- Select target currency from dropdown
- Click "Convert" to get real-time exchange rate
- Result displayed in popup message
Example: 100 USD to EUR = 85.23 EUR
command
C:\Users\username\Documents\currencyExchangeCalculator> python currencyexchnageratecalculator.py
[Currency Exchange Calculator GUI Opens]
- Enter amount to convert
- Select base currency from dropdown
- Select target currency from dropdown
- Click "Convert" to get real-time exchange rate
- Result displayed in popup message
Example: 100 USD to EUR = 85.23 EUR
  1. Use the Application
    • Enter the amount to convert
    • Select source currency from dropdown
    • Select target currency from dropdown
    • Click β€œConvert” to get real-time exchange rate
 
## Explanation
 
1. The `import tkinter as tk` statement imports the Tkinter library for creating the GUI.
2. The `import requests` statement imports the requests library for making API calls.
3. The `win = Tk()` creates the main window for the application.
4. The `win.geometry("700x400")` sets the window size to 700x400 pixels.
5. The `def exchange():` function handles the currency conversion logic.
6. The `requests.get()` function fetches real-time exchange rates from the API.
7. The `response.json()` parses the JSON response from the API.
8. The `rates[converted_currency]` extracts the specific exchange rate.
9. The `messagebox.showinfo()` displays the conversion result in a popup.
10. The `ttk.Combobox()` creates dropdown menus for currency selection.
11. The `Button()` widget creates the convert button with the exchange function.
12. The currency list includes major world currencies for conversion.
 
## Next Steps
 
Congratulations! You have successfully created a Currency Exchange Rate Calculator GUI in Python. Experiment with the code and see if you can modify the application. Here are a few suggestions:
- Add more currencies to the selection list
- Implement historical exchange rate charts
- Add currency conversion history tracking
- Create offline mode with cached rates
- Implement currency rate alerts and notifications
- Add calculator-style number input
- Create currency trend analysis features
- Add favorite currency pairs
- Implement rate comparison between different providers
 
## Conclusion
 
In this project, you learned how to create a Currency Exchange Rate Calculator GUI in Python using Tkinter and API integration. You also learned about working with real-time data, JSON processing, and creating professional GUI applications. You can find the source code on [GitHub](https://github.com/Ravikisha/PythonCentralHub/blob/main/projects/beginners/currencyexchnageratecalculator.py)
 
## Explanation
 
1. The `import tkinter as tk` statement imports the Tkinter library for creating the GUI.
2. The `import requests` statement imports the requests library for making API calls.
3. The `win = Tk()` creates the main window for the application.
4. The `win.geometry("700x400")` sets the window size to 700x400 pixels.
5. The `def exchange():` function handles the currency conversion logic.
6. The `requests.get()` function fetches real-time exchange rates from the API.
7. The `response.json()` parses the JSON response from the API.
8. The `rates[converted_currency]` extracts the specific exchange rate.
9. The `messagebox.showinfo()` displays the conversion result in a popup.
10. The `ttk.Combobox()` creates dropdown menus for currency selection.
11. The `Button()` widget creates the convert button with the exchange function.
12. The currency list includes major world currencies for conversion.
 
## Next Steps
 
Congratulations! You have successfully created a Currency Exchange Rate Calculator GUI in Python. Experiment with the code and see if you can modify the application. Here are a few suggestions:
- Add more currencies to the selection list
- Implement historical exchange rate charts
- Add currency conversion history tracking
- Create offline mode with cached rates
- Implement currency rate alerts and notifications
- Add calculator-style number input
- Create currency trend analysis features
- Add favorite currency pairs
- Implement rate comparison between different providers
 
## Conclusion
 
In this project, you learned how to create a Currency Exchange Rate Calculator GUI in Python using Tkinter and API integration. You also learned about working with real-time data, JSON processing, and creating professional GUI applications. You can find the source code on [GitHub](https://github.com/Ravikisha/PythonCentralHub/blob/main/projects/beginners/currencyexchnageratecalculator.py)

Was this page helpful?

Let us know how we did