Skip to content
Related Articles

Related Articles

PyQt5 – Application to get the price of BitCoin
  • Last Updated : 04 May, 2020

In this article we will see how we can make a PyQt5 application which tells the real time price of the bitcoin.

Modules required and Installation:

PyQt5 : PyQt is a Python binding of the cross-platform GUI toolkit Qt, implemented as a Python plug-in. PyQt is free software developed by the British firm Riverbank Computing.

pip install PyQt5

Requests : Requests allows you to send HTTP/1.1 requests extremely easily. There’s no need to manually add query strings to your URLs.

pip install requests

Beautiful Soup : Beautiful Soup is a library that makes it easy to scrape information from web pages. It sits atop an HTML or XML parser, providing Pythonic idioms for iterating, searching, and modifying the parse tree.

pip install beautifulsoup4

Steps to make application to get real time price of bitcoin –

1. Create a window and sets its dimension and title
2. Create a label to sHow the price
3. Create a push button
4. Add action to the push button
5. Inside the action with the help of requests fetch the data for price of bit coin
6. Using beautiful soup convert the data into html code and find the price and save it in variable
7. Change the text of the label, set price as text

Below is the implementation –

# importing libraries
from bs4 import BeautifulSoup as BS
import requests
from PyQt5.QtWidgets import * 
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import * 
from PyQt5.QtCore import * 
import sys
class Window(QMainWindow):
    def __init__(self):
        # setting title
        self.setWindowTitle("PyQt5 Bit Coin ")
        # setting geometry
        self.setGeometry(100, 100, 400, 600)
        # calling method
        # showing all the widgets
    # method for widgets
    def UiComponents(self):
        # creating label to show bit coin price
        self.label = QLabel("//BIT-COIN//", self)
        # setting geometry of label
        self.label.setGeometry(50, 150, 300, 50)
        # setting its alignment
        # setting font to the label
        self.label.setFont(QFont('Times', 15))
        # setting border to the push button
        self.label.setStyleSheet("border : 3px solid black;")
        # creating push button to show current price
        button = QPushButton("Show price", self)
        # setting geometry to push button
        button.setGeometry(150, 300, 100, 40)
        # adding method to the push button
        # setting tool tip to button
        button.setToolTip("Press to get Bit Coin Price")        
    def show_price(self):
        # url of the bit coin price
        url = " = bitcoin + price"
        # getting the request from url
        data = requests.get(url)
        # converting the text
        soup = BS(data.text, 'html.parser')
        # finding metha info for the current price
        ans = soup.find("div", class_="BNeawe iBp4i AP7Wnd").text
        # setting this price to the label
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app

Output :

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :