×

Rank Based Percentile GUI Calculator using PyQt5 in Python

PyQt5:

PyQt5 is one of several solutions that Python offers for creating GUI applications. Cross-platform GUI toolkit PyQt5 is a collection of Python interfaces for Qt version 5. With the capabilities and convenience of use that this library offers, one can create an interactive computer program very quickly.  Front-end and Back-end make up a GUI application. In order to speed up development & allow more time to be spent on back-end tasks, PyQt5 has developed a tool called "QtDesigner" that allows one to drag and drop elements to create the front-end. Riverbank Computing is the company in charge of developing and maintaining PyQt. A most recent stable version is PyQt6. The PyQt main version's release cycle matches Qt's, as per the release history. The PyQt codebase is a complex system with both C++ and Py code at its core. It is therefore more difficult to create and download it from the sources than other Python libraries. Even more detailed installation instructions may be found in the instructions for the specific PyQt version we want to utilise. It comes with installation instructions for both the GPL and the paid versions. Before the window shows on the screen, a few essential concepts regarding the organisation of applications in the Qt world must be explained. Unless you're already familiar with event loops, you can proceed to the next part without risk. The cornerstone of all Qt programs is the QApplication class. For each application to function, there must be a single QApplication object.

Installation:

pip install pyqt5
pip install pyqt5-tools

CODE:

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):
        super().__init__()
        self.setWindowTitle("Python ")  
        self.w_width = 400  
        self.w_height = 400
        self.setGeometry(100, 100, self.w_width, self.w_height)  
        self.UiComponents()
        self.show()  
    # method for components
    def UiComponents(self):  
        head = QLabel("Percentile Calculator", self)  
        head.setGeometry(0, 10, 400, 60)  
        font = QFont('Times', 15)
        font.setBold(True)
        font.setItalic(True)
        font.setUnderline(True)  
        head.setFont(font)  
        head.setAlignment(Qt.AlignCenter)  
        color = QGraphicsColorizeEffect(self)
        color.setColor(Qt.darkCyan)
        head.setGraphicsEffect(color)  
        t_label = QLabel("Total Participants", self)  
        t_label.setAlignment(Qt.AlignCenter)
        t_label.setGeometry(20, 100, 170, 40)
        t_label.setStyleSheet("QLabel"
                              "{"
                              "border : 2px solid black;"
                              "background : rgba(70, 70, 70, 35);"
                              "}")
        t_label.setFont(QFont('Times', 9))  
        self.total = QLineEdit(self)  
        onlyInt = QIntValidator()
        self.total.setValidator(onlyInt)  
        self.total.setGeometry(200, 100, 180, 40)
        self.total.setAlignment(Qt.AlignCenter)
        self.total.setFont(QFont('Times', 9))  
        r_label = QLabel("Rank ", self)  
        r_label.setAlignment(Qt.AlignCenter)
        r_label.setGeometry(20, 150, 170, 40)
        r_label.setStyleSheet("QLabel"
                              "{"
                              "border : 2px solid black;"
                              "background : rgba(70, 70, 70, 35);"
                              "}")
        r_label.setFont(QFont('Times', 9))  
        self.rank = QLineEdit(self)  
        onlyInt = QIntValidator()
        self.rank.setValidator(onlyInt)  
        self.rank.setGeometry(200, 150, 180, 40)
        self.rank.setAlignment(Qt.AlignCenter)
        self.rank.setFont(QFont('Times', 9))    
        calculate = QPushButton("Calculate Percentile", self)  
        calculate.setGeometry(125, 220, 150, 40)  
        calculate.clicked.connect(self.calculate_action)  
        self.result = QLabel(self)  
        self.result.setAlignment(Qt.AlignCenter)
        self.result.setGeometry(50, 300, 300, 60)
        self.result.setStyleSheet("QLabel"
                                  "{"
                                  "border : 3px solid black;"
                                  "background : white;"
                                  "}")
        self.result.setFont(QFont('Arial', 11))  
    def calculate_action(self):    
        students = self.total.text()  
        rank = self.rank.text()  
        if len(students) == 0 or len(rank) == 0:
            return  
        students = int(students)  
        rank = int(rank)  
        if students == 0 or rank == 0:
            return  
        result = round((students - rank) / students * 100, 3)      
        self.result.setText("Percentile : " + str(result))
App = QApplication(sys.argv)
window = Window()  
sys.exit(App.exec())

CODE EXPLANATION:

Importing the required libraries that are PyQt5.QtWidgets, PyQt5.QtCore, qtGui, sys. From the function Window and init self, we settle a title named Python for the header window to show on brief. We declare a title, include the width and height, and set a perfect geometry with Ui components. Creating another function named UiComponents by creating a head label and setting the geometry to head and font with QFont to set different types like bold, italic, and underline. After setting the font, we go for the color to color with QGraphics colorize effect and create a label called Total partitions and properties to the label. Then creating a QLineEdit object to get the total participants and accept only the number as valid input by setting properties to the line edit with setGeometry and creating a rank label by setting properties to the label. Then we create a QLineEdit object to get the rank. Accepting only the number as input and setting properties to the line edit, we create a push button with geometry and add action to the calculate button. Finally, we create the instance of our window to start the app with the library sys.

OUTPUT:

Rank-Based Percentile GUI Calculator using PyQt5 in Python

Related Topics

Python Parse Text File

We will learn different ways of read text records in Python. TL;DR The accompanying tells the best way to read all texts from the readme.txt document into a string: with open('readme.txt') as f: lines...

5 minutes read.

GUI Calendar using Tkinter 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...

3 minutes read.

Python for Data Analysis

Data analysis uses various techniques to read, illustrate, manipulate and evaluate a particular data. You can have access to the data and keep the data updated regularly. You can append...

4 minutes read.

Python variance() function

Variance The variance is the average of the square deviations from the mean. The variance will measure the spread of the dataset from its mean or median value. The greater the...

4 minutes read.

How to check if the dictionary is empty in Python?

What is a dictionary in Python? A directory is a collection of data but data is not ordered. Unlike other data types, it does not hold a single value as its...

3 minutes read.

Time. Sleep() in Python

Python time sleep () function suspends execution for a certain seconds given by user. Time sleep () syntax: Sleep(seconds) Limitations: The number of seconds to be suspends the code as per its requirements. Returns: Void The execution...

3 minutes read.

Python pycountry

What is Pycountry? 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...

4 minutes read.

Python Basics

In this tutorial, we will learn about the basics of Python, a very famous programming language. This tutorial will help you understand the language better if you start with python....

8 minutes read.

Drop() Function in Python

Drop() Function: The python programming language consists of various libraries; some of them are pandas and matplotlib. Data scientists mainly use the pandas library to analyze the data more easily and...

3 minutes read.

Python try except

Before diving right into loads of syntax we need to know what does try except is used for and how it helps users in writing programs What is Python try except? Python...

5 minutes read.

How to add 2 lists in Python?

In Python, a list is defined as a data structure that contains a sequence of elements. It can contain any kind of data type inside it but in order to concatenate two...

3 minutes read.

Python ascii() Function

Python ascii() Function The ascii() function returns a readable version of any object (Strings, Tuples, Lists, etc). This function will replace any non-ascii characters with escape characters. Syntax ascii(object) Parameter object:  An object, like String, List, Tuple, Dictionary, etc. Return This...

1 minute read.

Python's Qstandarditemmodel

Python More interactive and user-friendly than any other programming language is Python. Many libraries are used by the python programming language to speed up procedures. Python can be used to develop...

3 minutes read.

Python Percentage Sign

In Python, the percentage sign significantly completes two things. They are: It goes about as a Modulo administrator. It helps in string organizing. Allow us to see every one of them plainly. Modulo operator: Like...

2 minutes read.

Python JSON

In this tutorial, we will learn about JSON in the Python programming language. We will focus on its features, Guidelines to be kept in mind while writing its syntax, the...

3 minutes read.

Python Control Statements

Control statements are under the roof topic of loops and loops in python are defined as iteratively and repeatedly working on source code. Loop control statements are defined as they...

3 minutes read.

Flutter Python

The flutter is a frame work available in the python programming language, to create web applications, mobile apps. The flutter is generally used for the development of the backend of...

3 minutes read.

Python Statistical Module

Python Statistical Module The Python statistical module provides various functions that we can use in our Python program, to perform mathematical statistics operations on the numerical data given to us. The...

8 minutes read.

Programs for Printing Pyramid Patterns in Python

<!-- wp:paragraph --><p>Python supports printing patterns using basic for loops. The number of rows is handled by the first outer loop, while the number of columns is handled by the...

9 minutes read.

How to Call a Function in Python

How To Call a Function in Python Functions are the well-defined and structured piece of code that is used to implement specific functionality. Calling a function in python is the best...

4 minutes read.