×

Application to get live USD/INR rate Using Tkinter in Python

Tkinter:

The standard Python technique for building Graphical User Interfaces (GUIs) is Tkinter, which is included in all popular Python distributions. The only framework included in the Python standard library is this one. On top of Tk, this Python framework serves as a thin object-oriented layer that provides access to the Tk toolkit. The Tk toolkit is a cross-platform set of "graphical control elements," also called widgets, used to build application interfaces. This framework gives Python users a quick and easy way to build GUI elements with the Tk toolkit's widgets. In a Python application, Tk widgets can create buttons, menus, data fields, etc.

Once created, these graphic elements can be connected to or work with other widgets, features, functionality, processes, or data.

Tkinter bridges the gap between Python's execution model and Tcl's, built around cooperative multitasking. Like Python, Tcl is an interpreted dynamic programming language. Although it is an overall programming language that can be used independently, it is most frequently used in C programs as a scripting motor or as an interaction with the Tk toolbox. The Tcl library has a C interface that enables users to add custom Tcl or C commands, run Tcl commands and scripts, and manage one or more Tcl interpreter instances. Each interpreter has a queue for events that can be used to send and process events.

Syntax:

from tkinter import *
from tkinter import ttk

Advantages of Tkinter:

This promotes flexibility in handling GUI incidents, which makes the code base run more smoothly. Qt is more than just a framework; it uses a variety of native platform APIs for networking, database development, and other uses. Through a unique API, it gives them direct access.

Disadvantages of Tkinter:

Tkinter doesn't have any advanced widgets. There isn't a tool like Qt Designer for Tkinter in it. Its user interface is unreliable. Tkinter can be challenging to debug at times. It's not entirely in Python.

The libraries imported were:

  • Tkinter
  • BeautifulSoup

BeautifulSoup:

A Python package called Beautiful Soup can extract data from XML and HTML files. It provides natural means of traversing, searching, and altering the parse tree in conjunction with your preferred parser. Programmers frequently save days or hours of labour thanks to it. There is a tonne of unstructured data and information readily available today. The readily accessible data can be challenging to read at times. Web scraping is a highly helpful technique for turning unstructured information into data that is simpler to read and analyse, regardless as to how the data is currently available. In other words, web scraping is one method for gathering, arranging, and analysing this massive amount of data. Therefore, let's first define web-scraping. Data extraction, copying, and filtering are all just parts of the scraping process. Web-scraping refers to the process of collecting information or streams from the internet. The process of extracting data from the web is called web scraping, also known as information extraction or web harvesting. In essence, web scraping gives programmers a mechanism to gather and examine internet data.

The Beautiful Soup is a Library for python that bears the same name as a poem by Lewis Carroll from "Alice's Adventures in Wonderland." A Python tool called "Beautiful Soup" helps organise and arrange complicated web data by repairing terrible HTML and presenting it to us in clearly navigable XML structures by parsing the undesirable material, as the name implies.

CODE:

from tkinter import *
import requests
from bs4 import BeautifulSoup
 
def getdata(url):
    r = requests.get(url)
    return r.text
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! something wrong")
master = Tk()
master.configure(bg='light grey')
result = StringVar()
rate = StringVar()
per_rate = StringVar()
time = StringVar()
inc = StringVar()
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)
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)
b = Button(master, text="Show", command=get_info, bg="Blue").grid(row=0)
 
mainloop()

CODE EXPLANATION:

Importing all the required modules to get processed[winapps]. Apps method is attached for output. Use set() method to set the data like the name of the application, version of the application, installation date of the application, publisher of the application. The uninstalling string required for the application and set background using configure()[light grey] ,create variable classes in tkinter[name , version , publisher , install_date , publisher, uninstall_string then create label for each information using label() these labels() are positioned by using grid() method[select row as per the design. We also create entry box to enter the application using entry(). In entry box we also insert buttons, rows , columns , checkbox and lot many.

OUTPUT:

Application to get live USD/INR rate Using Tkinter in Python

Related Topics

Python String istittle() method

Python String istittle() method The string.istittle() method returns a boolean value true if the string is a titlecased string and there is at least one character, for example uppercase characters may...

2 minutes read.

Reading a File Line by Line in Python

Introduction In this tutorial, we will learn about reading files in python line by line. Before reading the files, let us know a little information about the files first. Files A file is...

6 minutes read.

Python program to count and display vowels in a string

Python program to count and display vowels in a string This python program counts the vowels in a string and displays them on the screen. We can do this in several...

2 minutes read.

Python vs HTML

Python and HTML are not comparable since they are two separate categories of programming languages. Building the structures and layouts of a web page or app requires the usage of HTML,...

8 minutes read.

Python Decorator

Python Decorator: A Decorator is an interesting feature of Python that helps the user design patterns and insert a new functionality to an existing object without making any modifications in...

6 minutes read.

Python Matrix Operations

Python Matrix In this section of the Python tutorial, we will look at the introduction of the matrix in Python programming. We will perform many operations on the Python matrix using...

21 minutes read.

Python List extend() method

Python List extend() method The list.extend() method extends the list by appending all the items from the iterable. Syntax list.extend(iterable) Parameter iterable: It is a required parameter which represents any iterable unlike list, set, tuple, etc. Example 1 # Python...

1 minute read.

Python Project Ideas for Advanced Developers

Best Python Project Ideas for Advanced Developers Python is an object-oriented, high-level, interpreted programming language created by a developer known Guido Van Rossum. Python is one of the languages that gathered...

9 minutes read.

Python Identifiers

Identifiers in Python User-defined names are identifiers in Python that are used to name variables, functions, classes, modules, and other things. You can create Python identifiers using these rules: As an identifier...

4 minutes read.

How to build a Virtual Assistant Using Python

What is a virtual assistant? A virtual assistant is a new and very interesting concept in today’s world. When we hear the word “Virtual Assistant”, we can easily visualize “Jarvis or...

8 minutes read.

Get index of element in array in python

Index : Index is a number where the element is located in the given list. In other words it is the position of the element in the list. Index can also...

4 minutes read.

How to create a list in Python?

How to create a list in python Python is known for its versatility and its data structures help us to perform different kinds of operations on various datasets irrespective of their...

4 minutes read.

Python bin() function

Python bin() function The bin() function in Python returns the binary version for the specified integer. Syntax bin(x) Parameter n: This parameter represents an integer or int value. Return This function returns a binary string for the specified integer...

1 minute read.

Self in Python

 “self" is neither a keyword nor has a special meaning in Python, but it has a place and a job to do in Object-oriented programming. When we create a class...

6 minutes read.

Latest Project Ideas using Python 2024

Python is one of the well-known languages for programming in the contemporary domain of computer science. The demand to adopt Python for IT purposes is steadily increasing because of its...

7 minutes read.

Standard GUI Unit Converter using PyQt5 in Python

GUI: A graphical interface (GUI) is a user interface that lets users interact with electronic devices like computers and smartphones by using menus, icons, and other visual cues (graphics). In contrast...

6 minutes read.

Comment starts with the symbol in Python

Python programming language: Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a...

3 minutes read.

Python List copy() method

Python List copy () method The list.copy () method returns a shallow copy of the list. Syntax list.copy() Parameter NA Return This function returns the copy for the given list. Example 1 # Python program explaining # the list.copy() method # passing the...

1 minute read.

Python String lstrip() method

Python String lstrip() method The string. lstrip () method in Python returns a copy of the string with leading characters removed (based on the string argument passed). Syntax string.lstrip([chars]) Parameter chars(optional): This parameter represents a...

1 minute read.

Python Infinity

Introduction We will discover how to define an infinite number in Python in this tutorial. Infinity, as we all know, is a value that cannot be defined and can either be...

5 minutes read.