Currency Converter in Python - Beginner Project

NeuralNine · Intermediate ·💻 AI-Assisted Coding ·2y ago

Key Takeaways

This video demonstrates how to build a simple currency converter in Python using a graphical user interface and a third-party package called Forex Python. The application allows users to choose a currency, enter an amount, and convert it to another currency.

Full Transcript

what is going on guys welcome back in this video today we're going to build a currency converter in Python so let us get right into [Music] it all right so let us take a brief look at what we're going to end up with here at the end of this video this is going to be our final application a currency converter a simple graphical user interface with two drop downs where you can choose a currency for example USD to Euro and then we can type an amount for example $5 and then we can click convert and we get 5 usds equal to € 4.64 and you can of course change the currency you can also get theate itself if you type one and that is what we're going to build it's a very simple application it's a very beginner friendly project we're going to learn how to work with graphical user interfaces and we're going to use a third party package that gets us the conversion rates so this what we're going to build and we're going to start by installing the package that I just talked about so we're going to say pip or pip pre-install Forex Das python this is the package that gets us the uh conversion rates and then we're going to get right into it by importing TK inter s TK this is going to be for the graphical user interface it's a core python package and then we're going to also from Forex python import currency rates um actually from Forex python. converter import currency rates now as far as I know this package does not have any functionality that gives us a collection of the available currencies so we're going to just Define a list of the currencies that we want to support so we can say something like common currencies and we can say uh for example USD Euro great breaden pound you need to use of course the correct symbols because they are identifiers for the currencies uh Japanese Yen we can use Canadian dollars we can use Australian dollars uh we can use the Swiss currency and New Zealand dollars and yeah basically you can add whatever you want as long as it's a valid currency and then we're going to build everything else as a class so we're going to say class currency currency converter and we're going to define the graphical user interface in the init methods so in the Constructor basically we're going to say self root is equal to tk. TK which is just our basic window we're going to say self root title is going to be currency converter self root geometry is let's say 200 * uh 180 and then what we're going to do is we're going to Define string variables and option menus now the string variables are going to be the currencies that are chosen so from the list here basically and the option menu is the drop down that then is connected to that variable so what we're going to do is we're going to say self. from VAR is going to be equal to a string variable so TK string uh variable and it's going to have root as a parent and we're going to set it to be uh the default to have a default value of USD and then we're going to say from menu is going to be equal to TK option menu self root self from uh VAR which is our string variable and then we need to um unpack the common currencies here to provide them as a uh list of values for the dropdown so this is just a drop- down menu we say it's part of the root window uh the value of it is the string variable here and or this is the string variable associated with it and the possible values are uh the list unpacked so all these values here all right uh then we're going to just pack all this so from menu pack we're going to use a padding of one um on the vertical axis and then I can just copy this and I can repeat the same thing just that I'm going to replace from with two and we're going to set the default here to Euro and the rest is actually the same then we need to have a label for the amount for the final conversion so self amount or actually no we need the label in the end we need to have the um the label for the text box for the entry and then we need to have another label at the bottom uh for the actual converted amount so we're going to say amount label here is going to be equal to TK label um going to be part of self root and the text is just going to be amount I'm going to pack this as well padding y equal 1 and then we want to add an amount entry which is just going to be a simple text box so TK entry part of self root and uh actually we don't need anything else here so just pack it as well with a padding y = to 1 and then we're going to have the convert button and the final result label so self. convertor button is going to be equal to TK button self root text is going to be convert obviously and the command is going to be a function that we don't have yet and this is going to be the convert currency method so we're going to Define it down here convert currency and we're going to just add a pass for now so that we have the function or the method but it doesn't do anything uh and then we're going to say self. convert button pack again with a padding of one on the Y AIS and finally we want to have the result so the result label is going to be equal to tk. label um self. root then the text is going to be empty by default and we're going to pack pack this as well so result label pack with a padding off you guessed it one there you go so in the end just a simple self root main Loop call so that we actually have our user interface running and the only magic now needs to happen in the actual convert currency function which is not too difficult to implement so we're just going to say try uh we do a try to avoid having uh problems with uh invalid numbers and problems with invalid currencies so we're going to try to do the conversion but it can fail of course so we're going to say from Curren is going to be equal to self. from variable get so this gets us the value then uh two currency two variable and then the amount is a typ casted uh float here so we typ cast the content of self amount entry. get so we get the content from the amount entry then we typ cast it to a float that's the amount and then we get the conversion rates so we can say C rates is equal to currency rates and then we can say that the rate we need is uh the following we want to get from C rates get the rate and then from currency to currency this will give us a rate and then we just need to have a converted amount which is going to be the amount times the rate obviously and all we need to do then is we need to take the result label and change the text so the text is then going to be a formatted string we're going to say amount from currency equals converted amount up until two decimal places um and then two currency there you go um that's basically it what's the problem here yeah we don't have an accept block so we need to also say accept and uh yeah depending on what it is if it's a value error we're going to say uh let's just copy this and we're going to change the text here to please enter a valid number and if it's uh any other exception we're going to say error occurred this is how you write that I think so all right so in order to actually use this now all we have to do is we have to create an instance of this class so if uncore name uncore uncore equals uncore uncore maincore uncore then currency converter constructed there you go and we have our application I can choose uh some currency I can enter an amount I can get a conversion there you go and of course if I get the same uh currency I get of course the same conversion so yeah this is how you build a simple currency converter in Python so that's it for today's video I hope you enjoyed it and hope you learned something if so let me know by hitting a like button and leaving a comment in the comment section down below and of course don't forget to subscribe to this Channel and hit the notification Bell to not miss a single future video for free other than that thank you much for watching see you in the next video and bye

Original Description

In this video, we build a currency converter in Python with a GUI. ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾ 📚 Programming Books & Merch 📚 🐍 The Python Bible Book: https://www.neuralnine.com/books/ 💻 The Algorithm Bible Book: https://www.neuralnine.com/books/ 👕 Programming Merch: https://www.neuralnine.com/shop 💼 Services 💼 💻 Freelancing & Tutoring: https://www.neuralnine.com/services 🌐 Social Media & Contact 🌐 📱 Website: https://www.neuralnine.com/ 📷 Instagram: https://www.instagram.com/neuralnine 🐦 Twitter: https://twitter.com/neuralnine 🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/ 📁 GitHub: https://github.com/NeuralNine 🎙 Discord: https://discord.gg/JU4xr8U3dm
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from NeuralNine · NeuralNine · 0 of 60

← Previous Next →
1 Visualizing Stock Data With Candlestick Charts in Python
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
2 Python Beginner Tutorial #1 - Installation and First Program
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
3 Python Beginner Tutorial #2 - Variables and Data Types
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
4 Python Beginner Tutorial #3 - Operators and User Input
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
5 Python Beginner Tutorial #4 - If Statements and Conditions
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
6 Python Beginner Tutorial #5 - Loops
Python Beginner Tutorial #5 - Loops
NeuralNine
7 Python Beginner Tutorial #6 - Sequences and Collections
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
8 Python Beginner Tutorial #7 - Functions
Python Beginner Tutorial #7 - Functions
NeuralNine
9 Python Beginner Tutorial #8 - Exception Handling
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
10 Python Beginner Tutorial #9 - File Operations
Python Beginner Tutorial #9 - File Operations
NeuralNine
11 Python Beginner Tutorial #10 - String Functions
Python Beginner Tutorial #10 - String Functions
NeuralNine
12 Python Intermediate Tutorial #1 - Classes and Objects
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
13 Python Intermediate Tutorial #2 - Inheritance
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
14 Python Intermediate Tutorial #3 - Multithreading
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
15 Python Intermediate Tutorial #4 - Synchronizing Threads
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
16 Python Intermediate Tutorial #5 - Events and Daemon Threads
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
17 Python Intermediate Tutorial #6 - Queues
Python Intermediate Tutorial #6 - Queues
NeuralNine
18 Python Intermediate Tutorial #7 - Sockets and Network Programming
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
19 Python Intermediate Tutorial #8 - Database Programming
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
20 Python Intermediate Tutorial #9 - Recursion
Python Intermediate Tutorial #9 - Recursion
NeuralNine
21 Python Intermediate Tutorial #10 - XML Processing
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
22 Python Intermediate Tutorial #11 - Logging
Python Intermediate Tutorial #11 - Logging
NeuralNine
23 Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
24 Python Data Science Tutorial #2 - NumPy Arrays
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
25 Python Data Science Tutorial #3 - Numpy Functions
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
26 Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
27 Python Data Science Tutorial #5 - Subplots and Multiple Windows
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
28 Python Data Science Tutorial #6 - Matplotlib Styling
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
29 Python Data Science Tutorial #7 - Bar Charts with Matplotlib
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
30 Python Data Science Tutorial #8 - Pie Charts with Matplotlib
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
31 Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
32 Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
33 Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
34 Python Data Science Tutorial #12 - Pandas Series
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
35 Python Data Science Tutorial #13 - Pandas Data Frames
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
36 Python Data Science Tutorial #14 - Pandas Statistics
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
37 Python Data Science Tutorial #15 - Pandas Sorting and Functions
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
38 Python Data Science Tutorial #16 - Pandas Merging Data Frames
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
39 Python Data Science Tutorial #17 - Pandas Queries
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
40 Python Machine Learning Tutorial #1 - What is Machine Learning?
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
41 Python Machine Learning Tutorial #2 - Linear Regression
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
42 Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
43 Python Machine Learning #4 - Support Vector Machines
Python Machine Learning #4 - Support Vector Machines
NeuralNine
44 Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
45 Python Machine Learning Tutorial #6 - K-Means Clustering
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
46 Python Machine Learning Tutorial #7 - Neural Networks
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
47 Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
48 Generating Poetic Texts with Recurrent Neural Networks in Python
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
49 Stock Portfolio Visualization with Matplotlib in Python
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
50 Analyzing Coronavirus with Python (COVID-19)
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
51 Making Text Images Readable Again with Python and OpenCV
Making Text Images Readable Again with Python and OpenCV
NeuralNine
52 Neural Networks Simply Explained (Theory)
Neural Networks Simply Explained (Theory)
NeuralNine
53 Motion Filtering with OpenCV in Python
Motion Filtering with OpenCV in Python
NeuralNine
54 Top 5 Programming Languages To Learn in 2020
Top 5 Programming Languages To Learn in 2020
NeuralNine
55 Simple TCP Chat Room in Python
Simple TCP Chat Room in Python
NeuralNine
56 Image Classification with Neural Networks in Python
Image Classification with Neural Networks in Python
NeuralNine
57 Edge Detection with OpenCV in Python
Edge Detection with OpenCV in Python
NeuralNine
58 S&P 500 Web Scraping with Python
S&P 500 Web Scraping with Python
NeuralNine
59 Simple Sentiment Text Analysis in Python
Simple Sentiment Text Analysis in Python
NeuralNine
60 Introduction - Algorithms & Data Structures #1
Introduction - Algorithms & Data Structures #1
NeuralNine

This video teaches you how to build a simple currency converter in Python using a graphical user interface and a third-party package. You will learn how to create a GUI, handle user input, and convert currency using the Forex Python package.

Key Takeaways
  1. Install the Forex Python package using pip
  2. Import the necessary libraries, including TKinter and Forex Python
  3. Define a list of supported currencies
  4. Create a graphical user interface using TKinter
  5. Define a function to handle the conversion of currency
  6. Use the Forex Python package to get the conversion rates
  7. Update the GUI with the converted amount
💡 The Forex Python package provides a simple way to get the current conversion rates for different currencies, making it easy to build a currency converter application.

Related AI Lessons

Up next
Azure Security Priorities for 2026: Identity, Governance, AI Security & Zero Trust
Valto Microsoft Specialists
Watch →