├── .gitignore ├── .gitattributes ├── demo.gif ├── icon.png ├── utils.py ├── README.md ├── main.py └── currency.json /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | .env -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aklilu-Mandefro/currency-converter-gui-using-python/HEAD/demo.gif -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Aklilu-Mandefro/currency-converter-gui-using-python/HEAD/icon.png -------------------------------------------------------------------------------- /utils.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | import requests 4 | from decouple import config 5 | 6 | 7 | API_KEY = config('API_KEY') 8 | API_ENDPOINT = 'https://api.currencyapi.com/v3/latest' 9 | 10 | 11 | def get_currencies() -> list: 12 | currency_codes = [] 13 | with open('currency.json') as f: 14 | currency_data = json.load(f) 15 | for currency in currency_data: 16 | code, _ = list(currency.items())[0] 17 | currency_codes.append(code) 18 | return sorted(currency_codes) 19 | 20 | 21 | def convert_currency(from_currency: str, to_currency: str, amount: float) -> float: 22 | query_params = { 23 | 'apikey': API_KEY, 24 | 'base_currency': from_currency, 25 | 'currencies': to_currency 26 | } 27 | response = requests.get(API_ENDPOINT, params=query_params) 28 | currency_data = response.json() 29 | exchange_rate = currency_data['data'][to_currency]['value'] 30 | exchanged_value = exchange_rate * amount 31 | return exchanged_value 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Currency Converter GUI Application Using Tkinter Python 2 | 3 | ## ✍️ How to Set Up Your Virtual Environment 4 | 5 | Before you start coding, you'll need to make sure you have all the necessary tools and libraries installed. To ensure that you have a clean and isolated environment, you'll create a virtual environment using `venv`. 6 | 7 | Create a project directory and navigate to it in the terminal: 8 | 9 | ```bash 10 | mkdir currency-converter 11 | cd currency-converter 12 | ``` 13 | Create a virtual environment named `env` using the following command: 14 | 15 | ```bash 16 | python -m venv env 17 | ``` 18 | Python now ships with the pre-installed `venv` library to create virtual environments. 19 | 20 | Activate the virtual environment like this: 21 | 22 | ```bash 23 | source env/bin/activate 24 | ``` 25 | Note: if you're on Windows, you'll need to use `source env/Scripts/activate` to activate the environment. 26 | 27 | You should see `(env)` in your terminal prompt, indicating that the virtual environment has been activated. 28 | 29 | How to Install the Libraries 30 | Now that you've created the virtual environment, you can install the following libraries: 31 | 32 | `requests`: The library helps you send requests on API endpoints. 33 | `python-decouple`: The library helps you read the values of environment variables. 34 | `pillow`: The library adds image processing capabilities to your Python interpreter. 35 | To install the libraries, run the following command: 36 | 37 | 38 | ```bash 39 | pip install requests python-decouple pillow 40 | ``` 41 | 42 | ### Preview of The Output 43 | 44 | ![Demo](demo.gif) 45 | To preview the output, just click on the play icon at the top right of this image 46 | 47 | ## Contribute to this project 48 | 49 | Thank you for browsing this repo. Any contributions you make are **greatly 50 | appreciated**. 51 | 52 | If you have a suggestion that would make this better, please fork the repo and 53 | create a pull request. You can also simply open an issue with the tag 54 | "enhancement". Don't forget to give the project a star! Thanks again! 55 | 56 | 1. Fork the Project 57 | 2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`) 58 | 3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`) 59 | 4. Push to the Branch (`git push origin feature/AmazingFeature`) 60 | 5. Open a Pull Request 61 | 62 | ## Please give this repo a ⭐ if you found it helpful. 63 | 64 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from tkinter import Tk, ttk 3 | 4 | from PIL import Image, ImageTk 5 | 6 | from utils import convert_currency, get_currencies 7 | 8 | # Colors 9 | WHITE_COLOR = "#FFFFFF" 10 | BLACK_COLOR = "#333333" 11 | BLUE_COLOR = "#0000FF" 12 | 13 | 14 | def convert(): 15 | amount = float(amount_entry.get()) 16 | from_currency = from_combo.get() 17 | to_currency = to_combo.get() 18 | converted_amount = convert_currency(from_currency, to_currency, amount) 19 | 20 | result_label['text'] = f'{to_currency} {converted_amount:.2f}' 21 | 22 | 23 | # Window Configuration 24 | window = Tk() 25 | window.geometry("300x320") 26 | window.title("Currency Converter") 27 | window.configure(bg=WHITE_COLOR) 28 | window.resizable(height=FALSE, width=FALSE) 29 | 30 | 31 | # Frames 32 | top_frame = Frame(window, width=300, height=60, bg=BLUE_COLOR) 33 | top_frame.grid(row=0, column=0) 34 | 35 | main_frame = Frame(window, width=300, height=260, bg=WHITE_COLOR) 36 | main_frame.grid(row=1, column=0) 37 | 38 | 39 | # Top Frame Widgets 40 | icon_image = Image.open('icon.png') 41 | icon_image = icon_image.resize((40, 40)) 42 | icon_image = ImageTk.PhotoImage(icon_image) 43 | app_name_label = Label(top_frame, image=icon_image, compound=LEFT, text="Currency Converter", height=3, padx=13, pady=30, 44 | anchor=CENTER, font=('Arial 16 bold'), bg=BLUE_COLOR, fg=WHITE_COLOR) 45 | app_name_label.place(x=0, y=0) 46 | 47 | # Main Frame Widgets 48 | result_label = Label(main_frame, text=" ", width=15, height=2, pady=7, padx=0, anchor=CENTER, 49 | font=('Ivy 16 bold'), bg=WHITE_COLOR, fg=BLACK_COLOR, relief=SOLID) 50 | result_label.place(x=50, y=10) 51 | 52 | from_label = Label(main_frame, text="From", width=8, height=1, pady=0, padx=0, anchor=NW, 53 | font=('Ivy 10 bold'), bg=WHITE_COLOR, fg=BLACK_COLOR, relief=FLAT) 54 | from_label.place(x=48, y=90) 55 | from_combo = ttk.Combobox(main_frame, width=8, justify=CENTER, font=('Ivy 12 bold'),) 56 | from_combo['values'] = (get_currencies()) 57 | from_combo.current(0) 58 | from_combo.place(x=50, y=115) 59 | 60 | to_label = Label(main_frame, text="To", width=8, height=1, pady=0, padx=0, anchor=NW, 61 | font=('Ivy 10 bold'), bg=WHITE_COLOR, fg=BLACK_COLOR, relief=FLAT) 62 | to_label.place(x=158, y=90) 63 | to_combo = ttk.Combobox(main_frame, width=8, justify=CENTER, font=('Ivy 12 bold'),) 64 | to_combo['values'] = (get_currencies()) 65 | to_combo.current(1) 66 | to_combo.place(x=160, y=115) 67 | 68 | amount_entry = Entry(main_frame, width=22, justify=CENTER, 69 | font=('Ivy 12 bold'), relief=SOLID) 70 | amount_entry.place(x=50, y=155) 71 | 72 | convert_button = Button(main_frame, text="Convert", width=19, padx=5, 73 | height=1, bg=BLUE_COLOR, fg=WHITE_COLOR, font=('Ivy 12 bold'), command=convert) 74 | convert_button.place(x=50, y=210) 75 | 76 | # Mainloop 77 | window.mainloop() 78 | -------------------------------------------------------------------------------- /currency.json: -------------------------------------------------------------------------------- 1 | [ 2 | {"ETB": "Ethiopian Birr" }, 3 | { "AED": "United Arab Emirates Dirham" }, 4 | { "AFN": "Afghan Afghani" }, 5 | { "ALL": "Albanian Lek" }, 6 | { "AMD": "Armenian Dram" }, 7 | { "ANG": "NL Antillean Guilder" }, 8 | { "AOA": "Angolan Kwanza" }, 9 | { "ARS": "Argentine Peso" }, 10 | { "AUD": "Australian Dollar" }, 11 | { "AWG": "Aruban Florin" }, 12 | { "AZN": "Azerbaijani Manat" }, 13 | { "BAM": "Bosnia-Herzegovina Convertible Mark" }, 14 | { "BBD": "Barbadian Dollar" }, 15 | { "BDT": "Bangladeshi Taka" }, 16 | { "BGN": "Bulgarian Lev" }, 17 | { "BHD": "Bahraini Dinar" }, 18 | { "BIF": "Burundian Franc" }, 19 | { "BMD": "Bermudan Dollar" }, 20 | { "BND": "Brunei Dollar" }, 21 | { "BOB": "Bolivian Boliviano" }, 22 | { "BRL": "Brazilian Real" }, 23 | { "BSD": "Bahamian Dollar" }, 24 | { "BTN": "Bhutanese Ngultrum" }, 25 | { "BWP": "Botswanan Pula" }, 26 | { "BYN": "Belarusian ruble" }, 27 | { "BYR": "Belarusian Ruble" }, 28 | { "BZD": "Belize Dollar" }, 29 | { "CAD": "Canadian Dollar" }, 30 | { "CDF": "Congolese Franc" }, 31 | { "CHF": "Swiss Franc" }, 32 | { "CLF": "Unidad de Fomento" }, 33 | { "CLP": "Chilean Peso" }, 34 | { "CNY": "Chinese Yuan" }, 35 | { "COP": "Coombian Peso" }, 36 | { "CRC": "Costa Rican Colón" }, 37 | { "CUC": "Cuban Convertible Peso" }, 38 | { "CUP": "Cuban Peso" }, 39 | { "CVE": "Cape Verdean Escudo" }, 40 | { "CZK": "Czech Republic Koruna" }, 41 | { "DJF": "Djiboutian Franc" }, 42 | { "DKK": "Danish Krone" }, 43 | { "DOP": "Dominican Peso" }, 44 | { "DZD": "Algerian Dinar" }, 45 | { "EGP": "Egyptian Pound" }, 46 | { "ERN": "Eritrean Nakfa" }, 47 | { "ETB": "Ethiopian Birr" }, 48 | { "EUR": "Euro" }, 49 | { "FJD": "Fijian Dollar" }, 50 | { "FKP": "Falkland Islands Pound" }, 51 | { "GBP": "British Pound Sterling" }, 52 | { "GEL": "Georgian Lari" }, 53 | { "GGP": "Guernsey pound" }, 54 | { "GHS": "Ghanaian Cedi" }, 55 | { "GIP": "Gibraltar Pound" }, 56 | { "GMD": "Gambian Dalasi" }, 57 | { "GNF": "Guinean Franc" }, 58 | { "GTQ": "Guatemalan Quetzal" }, 59 | { "GYD": "Guyanaese Dollar" }, 60 | { "HKD": "Hong Kong Dollar" }, 61 | { "HNL": "Honduran Lempira" }, 62 | { "HRK": "Croatian Kuna" }, 63 | { "HTG": "Haitian Gourde" }, 64 | { "HUF": "Hungarian Forint" }, 65 | { "IDR": "Indonesian Rupiah" }, 66 | { "ILS": "Israeli New Sheqel" }, 67 | { "IMP": "Manx pound" }, 68 | { "INR": "Indian Rupee" }, 69 | { "IQD": "Iraqi Dinar" }, 70 | { "IRR": "Iranian Rial" }, 71 | { "ISK": "Icelandic Króna" }, 72 | { "JEP": "Jersey pound" }, 73 | { "JMD": "Jamaican Dollar" }, 74 | { "JOD": "Jordanian Dinar" }, 75 | { "JPY": "Japanese Yen" }, 76 | { "KES": "Kenyan Shilling" }, 77 | { "KGS": "Kyrgystani Som" }, 78 | { "KHR": "Cambodian Riel" }, 79 | { "KMF": "Comorian Franc" }, 80 | { "KPW": "North Korean Won" }, 81 | { "KRW": "South Korean Won" }, 82 | { "KWD": "Kuwaiti Dinar" }, 83 | { "KYD": "Cayman Islands Dollar" }, 84 | { "KZT": "Kazakhstani Tenge" }, 85 | { "LAK": "Laotian Kip" }, 86 | { "LBP": "Lebanese Pound" }, 87 | { "LKR": "Sri Lankan Rupee" }, 88 | { "LRD": "Liberian Dollar" }, 89 | { "LSL": "Lesotho Loti" }, 90 | { "LTL": "Lithuanian Litas" }, 91 | { "LVL": "Latvian Lats" }, 92 | { "LYD": "Libyan Dinar" }, 93 | { "MAD": "Moroccan Dirham" }, 94 | { "MDL": "Moldovan Leu" }, 95 | { "MGA": "Malagasy Ariary" }, 96 | { "MKD": "Macedonian Denar" }, 97 | { "MMK": "Myanma Kyat" }, 98 | { "MNT": "Mongolian Tugrik" }, 99 | { "MOP": "Macanese Pataca" }, 100 | { "MRO": "Mauritanian ouguiya" }, 101 | { "MUR": "Mauritian Rupee" }, 102 | { "MVR": "Maldivian Rufiyaa" }, 103 | { "MWK": "Malawian Kwacha" }, 104 | { "MXN": "Mexican Peso" }, 105 | { "MYR": "Malaysian Ringgit" }, 106 | { "MZN": "Mozambican Metical" }, 107 | { "NAD": "Namibian Dollar" }, 108 | { "NGN": "Nigerian Naira" }, 109 | { "NIO": "Nicaraguan Córdoba" }, 110 | { "NOK": "Norwegian Krone" }, 111 | { "NPR": "Nepalese Rupee" }, 112 | { "NZD": "New Zealand Dollar" }, 113 | { "OMR": "Omani Rial" }, 114 | { "PAB": "Panamanian Balboa" }, 115 | { "PEN": "Peruvian Nuevo Sol" }, 116 | { "PGK": "Papua New Guinean Kina" }, 117 | { "PHP": "Philippine Peso" }, 118 | { "PKR": "Pakistani Rupee" }, 119 | { "PLN": "Polish Zloty" }, 120 | { "PYG": "Paraguayan Guarani" }, 121 | { "QAR": "Qatari Rial" }, 122 | { "RON": "Romanian Leu" }, 123 | { "RSD": "Serbian Dinar" }, 124 | { "RUB": "Russian Ruble" }, 125 | { "RWF": "Rwandan Franc" }, 126 | { "SAR": "Saudi Riyal" }, 127 | { "SBD": "Solomon Islands Dollar" }, 128 | { "SCR": "Seychellois Rupee" }, 129 | { "SDG": "Sudanese Pound" }, 130 | { "SEK": "Swedish Krona" }, 131 | { "SGD": "Singapore Dollar" }, 132 | { "SHP": "Saint Helena Pound" }, 133 | { "SLL": "Sierra Leonean Leone" }, 134 | { "SOS": "Somali Shilling" }, 135 | { "SRD": "Surinamese Dollar" }, 136 | { "STD": "São Tomé and Príncipe dobra" }, 137 | { "SVC": "Salvadoran Colón" }, 138 | { "SYP": "Syrian Pound" }, 139 | { "SZL": "Swazi Lilangeni" }, 140 | { "THB": "Thai Baht" }, 141 | { "TJS": "Tajikistani Somoni" }, 142 | { "TMT": "Turkmenistani Manat" }, 143 | { "TND": "Tunisian Dinar" }, 144 | { "TOP": "Tongan Paʻanga" }, 145 | { "TRY": "Turkish Lira" }, 146 | { "TTD": "Trinidad and Tobago Dollar" }, 147 | { "TWD": "New Taiwan Dollar" }, 148 | { "TZS": "Tanzanian Shilling" }, 149 | { "UAH": "Ukrainian Hryvnia" }, 150 | { "UGX": "Ugandan Shilling" }, 151 | { "USD": "US Dollar" }, 152 | { "UYU": "Uruguayan Peso" }, 153 | { "UZS": "Uzbekistan Som" }, 154 | { "VEF": "Venezuelan Bolívar" }, 155 | { "VND": "Vietnamese Dong" }, 156 | { "VUV": "Vanuatu Vatu" }, 157 | { "WST": "Samoan Tala" }, 158 | { "XAF": "CFA Franc BEAC" }, 159 | { "XAG": "Silver Ounce" }, 160 | { "XAU": "Gold Ounce" }, 161 | { "XCD": "East Caribbean Dollar" }, 162 | { "XDR": "Special drawing rights" }, 163 | { "XOF": "CFA Franc BCEAO" }, 164 | { "XPF": "CFP Franc" }, 165 | { "YER": "Yemeni Rial" }, 166 | { "ZAR": "South African Rand" }, 167 | { "ZMK": "Zambian Kwacha" }, 168 | { "ZMW": "Zambian Kwacha" }, 169 | { "ZWL": "Zimbabwean dollar" }, 170 | { "BTC": "Bitcoin" }, 171 | { "ETH": "Ethereum" }, 172 | { "BNB": "Binance" }, 173 | { "XRP": "Ripple" }, 174 | { "SOL": "Solana" }, 175 | { "DOT": "Polkadot" }, 176 | { "AVAX": "Avalanche" }, 177 | { "MATIC": "Matic Token" }, 178 | { "LTC": "Litecoin" }, 179 | { "ADA": "Cardano" } 180 | ] 181 | --------------------------------------------------------------------------------