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).
We will be using three different modules in this project:
These libraries can be installed with certain commands in terminal, if not present already.
Steps to be followed :
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
Step 4 : Apply filters to the available data to determine the currency's specifics and quality (increment/decrement).
'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 :
The output for the aforementioned code for creating an application to get live USD - INR rate using Tkinter is attached below as a screenshot.
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week