×

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

Pillow Python introduction and setup

Introduction Advanced image processing implies handling the picture carefully with the assistance of a PC. Utilizing picture handling we can perform activities like upgrading the picture, obscuring the picture, separating text...

4 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.

Parameter Passing in Python

In Python, when we characterize capabilities with default values for specific boundaries, it is said to have its contentions set as a possibility for the client. Clients can either pass their...

3 minutes read.

How to check data type in python

The data type represents the nature of a variable; it determines what kind of data it can store and what operations can be carried out on it. There are five...

4 minutes read.

Python K-Means Clustering

K-Means Clustering is a basic yet incredible calculation in information scienceThere are a plenty of true utilizations of K-Means clustering (a couple of which we will cover here)This far reaching...

25 minutes read.

Python Tricks: The Book

A Buffet of Awesome Python Features Dan Bader is the author of the book called Python Tricks . he is the owner and editor of Real Python and one of the...

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 Set union() method

Python Set union() method The set.union() method in Python returns a set that contains all items from the original set and all items from the specified sets. Syntax set.union(set1, set2...) Parameter set1- This parameter represents the first set...

2 minutes read.

Python List Size

Introduction The list data type in Python is an ordered, flexible collection. A list may also contain duplicate entries. To get the size of any object, use the len() function in...

6 minutes read.

What is Python 2

Python is a widely used high-level language. The initial work on developing python was begun in the late 1980s. In 1989, Guido Van Rossum started to work on it. Initially,...

3 minutes read.

Python String swapcase() method

Python String swapcase() method The string.swapcase() method in Python returns a copy of the string with uppercase characters converted to lowercase and vice versa. Syntax string.swapcase() Parameter NA Return This method returns a copy of the string...

1 minute 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.

How to Convert String to List In Python?

How to Convert String to List In Python? We all are familiar with what strings and lists are, let us have a quick revision on them- Strings are a sequence of characters...

4 minutes read.

Python hasattr() function

Python hasattr() function The hasattr() function in Python returns a Boolean value ‘True’ if the given object has the specified attribute, else it returns False. Syntax hasattr(object, name) Parameter object: it is a required parameter which represents an object. attribute:...

1 minute 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.

Python program to print calendar

Python program to print the calendar This article will explain how to print the calendar of month and year using Python's calendar module. It's a straightforward thing in Python by importing...

1 minute read.

Python Dictionary setdefault() method

Python Dictionary setdefault() method The dictionary.setdefault () method in Python returns the value of the item with the specified key. Syntax dictionary.setdefault(keyname, value) Parameter keyname- This parameter represents the keyname of the item you want...

1 minute read.

Python Hash Table

An Introduction to Hashing A technique which used to identify a particular object uniquely from a set of similar objects is known as Hashing. Some real-life examples of hashing implementations include: A...

9 minutes read.

Python Functionalities of Pillow Module

This instructional exercise is about "Pillow" library, one of the significant libraries of python for picture control. Pillow library of python, is an easy to use and also open source...

14 minutes read.

Python float()

Python float() class The float() class in Python returns a floating point number constructed from a number or string x. Syntax class float([x]) Parameter x: This parameter represents a number or a string that can be converted...

1 minute read.