Application to get live USD - INR rate using Tkinter in Python

In this lesson, we'll create a Python project that lets you convert between different currencies. We'll utilise the tkinter library to create a user interface. Therefore, creating a GUI application to get current value of USD to INR.

What is a Currency Converter ?

There are hundreds of different currencies in the globe, and each one has a different value when compared to the others, thus we need a currency converter. So, in order to translate the value of our money into another currency, we need a currency converter. This helps us to easily understand the value of a particular currency in our own currency.

In this project we will be focussing mainly on the current conversion rate of the United States Dollars (USD) to Indian Rupees (INR).

Requirements :

We will be using three different modules in this project:

  • Tkinter : To set up the GUI
  • Requests : To request for the link to extract data.
  • Bs4 : A Python package called Beautiful Soup can extract data from XML and HTML files.

These libraries can be installed with certain commands in terminal, if not present already.

Steps to be followed :

  • Take information from the provided URL. After choosing the appropriate place, copy the URL.
  • Utilize requests and the BeautifulSoup module to scrape the data.
  • Put that information into HTML
  • Find the necessary information, then filter

Explanation :

Step 1 : Import all necessary modules.

Step 2 : Creating a URL get method.

Step 3 : In order to transform the data (currency information) into HTML code, send the URL into the getinfo() method.

Here's the corresponding URL : https://finance.yahoo.com/quote/usdinr=X?ltr=1

Output:

Application to get live USD - INR rate using Tkinter in Python

Step 4 : Apply filters to the available data to determine the currency's specifics and quality (increment/decrement).

Output:

'74.3721-1.3801 (-0.39%) As of 7:30PM BST. Market open.'

Walking through the code :

Firstly, we will import the Tkinter and requests module and the BeautifulSoup module's class into our code.

Then, we will create a method getinfo() to generate the details from a URL and store them in the variable req after receiving it using get() method.

Then, we will create another method called get_data() in order to collect all the information from the html version of the URL mentioned and then convert it to required format from the BeautifulSoup module and storing it in different variables using the set() method.

Next, we will start with the main code of our program by first creating a GUI window from Tkinter and then setting it's background colour to light grey, using the configure() method.

Then, we created few variable classes in order to store the different data that is to be displayed on the window.

Next, we created labels using the Label widget to state the heading of all the respective text areas. We set the position of all the labels by the help of the grid() method.

Then, we defined corresponding labels to all the headings created previously by using the Label widget for displaying the information extracted. All these labels were placed precisely by the help of the grid() method.

Lastly, we created a Show button by using the Button widget, which on clicking will show the information extracted in an organized manner. This button will also be positioned using grid() method.

Complete code :

Output:

The output for the aforementioned code for creating an application to get live USD - INR rate using Tkinter is attached below as a screenshot.

Application to get live USD - INR rate using Tkinter in Python
Application to get live USD - INR rate using Tkinter in Python




Latest Courses