Python Tkinter GUI Script to Make a LIVE INR/USD Currency Converter Using BeautifulSoup4 and Requests Library Full Project For Beginners

Python Tkinter GUI Script to Make a LIVE INR/USD Currency Converter Using BeautifulSoup4 and Requests Library Full Project For Beginners

 

Welcome folks today in this post we will be making a live inr to usd currency converter using beautifulsoup4 and requests library in python. All the full source code of the application is shown below.

 

 

 

Get Started

 

 

 

In order to get started you need to install the following libraries by using the pip command

 

 

pip install requests

 

pip install tkinter

 

pip install bs4`

 

 

After installing all these libraries make an app.py file and copy paste the following code

 

app.py

 

 

# Import required modules 
from tkinter import *
import requests 
from bs4 import BeautifulSoup 



# user defined funtion 
# to extract currency details 
def getdata(url): 
    r = requests.get(url) 
    return r.text 

    
    
# Function to compute and display currency detalis 
def get_info(): 
    try: 
        htmldata = getdata("https://finance.yahoo.com/quote/usdinr=X?ltr=1") 
        soup = BeautifulSoup(htmldata, 'html.parser') 
        mydatastr = '' 
        for table in soup.find_all("div", class_="D(ib) Va(m) Maw(65%) Ov(h)"): 
            mydatastr += table.get_text() 
        list_data = mydatastr.split() 
        temp = list_data[0].split("-") 
        rate.set(temp[0]) 
        inc.set(temp[1]) 
        per_rate.set(list_data[1]) 
        time.set(list_data[3]) 
        result.set("success") 
    except: 
        result.set("Opps! someting wrong") 



# Driver Code        
# Create tkinter object 
master = Tk() 

# Set background color 
master.configure(bg='light grey') 

# Variable Classes in tkinter 
result = StringVar() 
rate = StringVar() 
per_rate = StringVar() 
time = StringVar() 
inc = StringVar() 

# Creating label for each information 
Label(master, text="Status :", bg="light grey").grid(row=2, sticky=W) 
Label(master, text="Current rate of INR :", 
    bg="light grey").grid(row=3, sticky=W) 
Label(master, text="Increase/decrease by :", 
    bg="light grey").grid(row=4, sticky=W) 
Label(master, text="Rate change :", bg="light grey").grid(row=5, sticky=W) 
Label(master, text="Rate of time :", bg="light grey").grid(row=6, sticky=W) 

# Creating lebel for class variable 
Label(master, text="", textvariable=result, 
    bg="light grey").grid(row=2, column=1, sticky=W) 
Label(master, text="", textvariable=rate, 
    bg="light grey").grid(row=3, column=1, sticky=W) 
Label(master, text="", textvariable=inc, bg="light grey").grid( 
    row=4, column=1, sticky=W) 
Label(master, text="", textvariable=per_rate, 
    bg="light grey").grid(row=5, column=1, sticky=W) 
Label(master, text="", textvariable=time, 
    bg="light grey").grid(row=6, column=1, sticky=W) 

# Create submit button 
b = Button(master, text="Show", command=get_info, bg="Blue").grid(row=0) 

mainloop()

 

READ  Python 3 FPDF Library Example to Convert Raw Text and Text File to PDF Full Tutorial For Beginners

 

Now if run this python app by typing the below command

 

python app.py

 

 

 

Leave a Reply