The Wayback Machine - https://web.archive.org/web/20241002162311/https://www.geeksforgeeks.org/rank-based-percentile-gui-calculator-using-tkinter/
Open In App

Rank Based Percentile Gui Calculator using Tkinter

Last Updated : 11 Dec, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. In this article, we will learn how to create a Rank Based – Percentile Gui Calculator application using Tkinter, with a step-by-step guide.

Prerequisites: 

To create a Tkinter:

  • Importing the module – Tkinter
  • Create the main window (container)
  • Add any number of widgets to the main window.
  • Apply the event Trigger on the widgets.

The GUI would look like below:

Let’s create a GUI-based simple Rank Based – Percentile Gui Calculator application: 

Below is the implementation:

Python3




# import all functions from the tkinter   
from tkinter import *
 
  
# Function to calculate the percentile 
def getPercentile() :
  
    # take a value from the respective entry boxes
    # get method returns current text as string
    students= int(total_participantField.get())
      
    rank = int(rankField.get())
  
    # variable to store the result upto 3
    # decimal points 
    result = round((students - rank) / students * 100,3);
  
    # insert method inserting the  
    # value in the text entry box.
    percentileField.insert(10, str(result))
    
      
# Function for clearing the  
# contents of all text entry boxes
def Clear():
      
    # deleting the content from the entry box
    rankField.delete(0, END)
      
    total_participantField.delete(0, END)
      
    percentileField.delete(0, END)
      
  
# Driver Code
if __name__ == "__main__" :
  
    # Create a GUI window
    gui = Tk()
    
    # Set the background colour of GUI window  
    gui.configure(background = "light green")
    
    # set the name of tkinter GUI window 
    gui.title("Rank Based- Percentile Calculator")
    
     # Set the configuration of GUI window
    gui.geometry("650x200")
  
    # Create a Rank: label 
    rank = Label(gui, text = "Rank", bg = "blue")
  
    # Create a And: label 
    andl = Label(gui, text = "And", bg = "blue")
    
    # Create a Total Participants : label
    total_participant = Label(gui,
                              text = "Total Participants",
                              bg = "blue")
  
    # Create a Find Percentile Button and
    # attached to getPercentile function
    find = Button(gui, text = "Find Percentile",
                  fg = "Black", bg = "Red",
                  command = getPercentile)
      
    # Create a Percentile : label 
    percentile = Label(gui, text = "Percentile", bg = "blue")
  
    # Create a Clear Button and attached
    # to Clear function
    clear = Button(gui, text = "Clear",
                   fg = "Black", bg = "Red",
                   command = Clear)
  
    # grid method is used for placing  
    # the widgets at respective positions  
    # in table like structure .
  
    # padx attributed provide x-axis margin 
    # from the root window to the widget.
    rank.grid(row = 1, column = 1,padx = 10)
  
    andl.grid(row = 1, column = 4)
                   
    total_participant.grid(row = 1, column = 6, padx = 10)
  
    # pady attributed provide y-axis
    # margin from the widget.   
    find.grid(row = 3, column = 4,pady = 10)
      
    percentile.grid(row = 4, column = 3,padx = 10)
      
    clear.grid(row = 5, column = 4,pady = 10)
  
    # Create a text entry box for filling or
    # typing the information.  
    rankField = Entry(gui)
      
    total_participantField = Entry(gui)
      
    percentileField = Entry(gui)
  
    # grid method is used for placing  
    # the widgets at respective positions  
    # in table like structure .
    rankField.grid(row = 1, column = 2)
      
    total_participantField.grid(row = 1, column = 7)
      
    percentileField.grid(row = 4, column = 4)
      
    # Start the GUI
    gui.mainloop()


Output : 

Code Explanation:

  1. The code starts by getting the number of students and the rank of those students.
  2. The code then creates two variables, students and rank.
  3. The getPercentile() function will take these numbers as input and calculate their percentile according to a set formula.
  4. The getPercentile() function first takes the value from the total_participantField box.
  5. This is the total number of participants in the study.
  6. Next, it gets the value from the rankField box.
  7. This is how many people have a particular rank in this study.
  8. Finally, getPercentile() calculates each student’s percentile according to this set formula: where x is equal to the value from total_participantField, y is equal to the value from rankField, and z is equal to 100%.
  9. The code calculates the percentile for a given set of values.
  10. The first step is to get the number of students and rank.
  11. Next, the code calculates the median and mode for these two values.
  12. The getPercentile() function then takes these two values as input and stores them in a new variable called students and rank respectively.
  13. Next, the percentile is calculated using the following equation: (students/total_participantField.get()) * 100
  14. The code starts by creating a window called “gui”.
  15. The window has a green background color.
  16. Next, the code sets up some basic properties of the window.
  17. It specifies that the title of the window is “Analyze” and that it should be displayed in a floating panel on the left side of the screen.
  18. The next line of code creates an instance of Tkinter, which is Python’s built-in GUI library.
  19. Next, the code sets up some basic properties for the window.
  20. It specifies that it should have a border around it and that its title bar should be hidden.
  21. Finally, the code assigns values to two variables: rankField and total_participantField.
  22. rankField stores information about students’ ranks while total_participantField stores information about all participants in the study (i.e., both students and non-students).
  23. Next, the code calculates student ranks using round() function and inserts them into rankField variable.
  24. Then, it calculates participant counts using count() function and inserts them into total_participantField variable.
  25. Finally, it uses percentile() function to calculate percentage distributions for each rank group (i.e., 1st through 10th grades).
  26. The code creates a window and sets the background color to light green.
  27. Next, it sets the name of the window to “Comprehend”.
  28. Finally, it creates an instance of Tkinter and begins setting up its various properties.
  29. The next block of code creates two text entry boxes – one for the rank field and one for the total_participant field.
  30. The code then calculates the percentage of students who are lower than the student’s rank and stores this value in the percentileField text entry box.
  31. The last block of code clears all of the text entry boxes by deleting their contents.
  32. The code creates three labels: rank, andl, and total_participant.
  33. The rank label has the text “Rank” and is blue.
  34. The andl label has the text “And” and is blue.
  35. The total_participant label has the text “Total Participants” and is blue.
  36. The code sets up the GUI window with a geometry of 650×200 pixels.
  37. It creates two Label objects, one for the rank label and one for the andl label.
  38. The rank object has the text “Rank” as its value, while the andl object has the text “And” as its value.
  39. Finally, the code creates a Total Participant object with the text “Total Participants” as its value.
  40. The code creates a Rank: label, an And: label, and a Total Participants: label.
  41. The Rank: label will display the rank of the data set, while the And: label will display whether all data sets have an equal number of participants or not.
  42. The Total Participants: label will display the total number of participants in each data set.
  43. The code starts with the creation of three widgets: a find percentile button, a percentile label, and a clear button.
  44. The find percentile button is attached to the getPercentile function.
  45. This function takes two arguments: the dataframe and the percentile rank.
  46. The code creates an instance of the Button class and sets its properties accordingly.
  47. The fg property specifies the foreground color, while bg specifies the background color.
  48. The command property specifies how to execute the function when clicked.
  49. The percentile label is created next and attached to the getPercentile function as well.
  50. Like the find percentile button, it also has a command property that allows you to specify how to execute it when clicked.
  51. Finally, we create a grid method that will help us place all of our widgets in table-like structure onscreen.
  52. We use this grid method to position both buttons at 0% (the first column) and 100% (the last column).
  53. The code creates a Find Percentile button and attached to it is a getPercentile function.
  54. The find widget will display the text “Find Percentile” and have a black background.
  55. The percentile label will also be created and have a blue background.
  56. Finally, two buttons are created, Clear and Percentile.
  57. Clear will have a black background and have the command “Clear” associated with it, while Percentile will have a red background and the command “Get Percentile” associated with it.
  58. The code then uses the grid method to place the widgets at respective positions in table like structure .
  59. This allows for easy positioning of all of the widgets on the screen.


Previous Article
Next Article

Similar Reads

Python | Simple GUI calculator using Tkinter
Prerequisite: Tkinter Introduction, lambda function Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter outputs the fastest and easiest way to create GUI a
6 min read
Python | Distance-time GUI calculator using Tkinter
Prerequisites : Introduction to Tkinter | Using google distance matrix API Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with tkinter outputs the fastest and easiest wa
7 min read
Python - Dynamic GUI Calculator using Tkinter module
Python provides many options for developing GUI like Kivy, PyQT, WxPython, and several others. Tkinter is the one that is shipped inbuilt with python which makes it the most commonly used out of all. Tkinter is easy, fast, and powerful. Beginners can easily learn to create a simple calculator using this article: Python | Simple GUI calculator using
3 min read
Ratio Calculator GUI using Tkinter
Prerequisite: Python GUI – tkinter Tkinter is the most commonly used library for developing GUI (Graphical User Interface) in Python. It is a standard Python interface to the Tk GUI toolkit shipped with Python. As Tk and Tkinter are available on most of the Unix platforms as well as on the Windows system, developing GUI applications with Tkinter be
3 min read
Scientific GUI Calculator using Tkinter in Python
Prerequisite: Python GUI – tkinter In this article, we are going to create GUI Scientific Calculator using Python. As you can see, calculating large numbers nowadays is difficult or time-consuming. We've created a simple Scientific Calculator GUI using Python that allows you to perform simple and complex calculations. To implement GUI we will use t
13 min read
Python - Compound Interest GUI Calculator using Tkinter
Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the Python GUI Libraries, Tkinter is the most commonly used method. In this article, we will learn how to create a Compound Interest GUI Calculator application using Tkinter. Let’s create a GUI-based Compound Interest Calculator application. Importing the mod
6 min read
Percentile rank of a column in a Pandas DataFrame
Let us see how to find the percentile rank of a column in a Pandas DataFrame. We will use the rank() function with the argument pct = True to find the percentile rank. Example 1 : # import the module import pandas as pd # create a DataFrame data = {'Name': ['Mukul', 'Rohan', 'Mayank', 'Shubham', 'Aakash'], 'Location' : ['Saharanpur', 'Meerut', 'Agr
1 min read
PyQt5 - Percentile Calculator
In this article we will see how we can create a percentile calculator using PyQt5, below is how the percentile calculator will look like GUI implementation steps 1. Create a heading label that display the calculator name 2. Create label and line edit pair for total students, label to show what user has to enter and line edit to enter text 3. Simila
4 min read
TensorFlow - How to stack a list of rank-R tensors into one rank-(R+1) tensor in parallel
TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks. TensorFlow provides build in methods to stack a list of rank-R tensors into one rank-(R+1) tensor in parallel. Methods Used: parallel_stack: This method accepts a list of Tensors and returns a Tensor with all values stac
2 min read
Pandas Dataframe rank() | Rank DataFrame Entries
Python is a great language for data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier.  Pandas DataFrame rank() method returns a rank of every respective entry (1 through n) along an axis of the DataFrame passed. The rank is retu
3 min read
Python | Create a GUI Marksheet using Tkinter
Create a python GUI mark sheet. Where credits of each subject are given, enter the grades obtained in each subject and click on Submit. The credits per subject, the total credits as well as the SGPA are displayed after being calculated automatically. Use Tkinter to create the GUI interface. Refer the below articles to get the idea about basics of t
8 min read
Python: Weight Conversion GUI using Tkinter
Prerequisites: Python GUI – tkinterPython offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter outputs the fastest and easiest way to create GUI applications. Crea
2 min read
Python | ToDo GUI Application using Tkinter
Prerequisites : Introduction to tkinter Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. In this article, we will learn how to create a ToDo GUI application using Tkinter, with a step-by-step guide. To create a tkinter : Importing the module – tkinter
5 min read
Python | GUI Calendar using Tkinter
Prerequisites: Introduction to Tkinter Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. Python with Tkinter outputs the fastest and easiest way to create GUI applications. In this article, we will learn how to create a GUI Calendar application using
4 min read
Sentiment Detector GUI using Tkinter - Python
Prerequisites : Introduction to tkinter | Sentiment Analysis using Vader Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. Python with Tkinter outputs the fastest and easiest way to create GUI applications. In this article, we will learn how to creat
4 min read
Python - Morse Code Translator GUI using Tkinter
Prerequisites : Introduction to tkinter | Morse Code Translator Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. Python with Tkinter outputs the fastest and easiest way to create GUI applications. In this article, we will learn how to create a Morse
6 min read
Python - SpongeBob Mocking Text Generator GUI using Tkinter
Prerequisites : Introduction to tkinter | SpongeBob Mocking Text Generator Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. Python with Tkinter outputs the fastest and easiest way to create GUI applications. In this article, we will learn how to cre
4 min read
Python - Spell Corrector GUI using Tkinter
Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. Python with Tkinter outputs the fastest and easiest way to create GUI applications. In this article, we will learn how to create a GUI Spell Corrector application using Tkinter, with a step-by-step gu
5 min read
Python - UwU text convertor GUI using Tkinter
Prerequisites :Introduction to tkinter | UwU text convertor Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter outputs the fastest and easiest way to crea
4 min read
GST Rate Finder GUI using Python-Tkinter
Prerequisites : Introduction to tkinter | Program to calculate GSTPython offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. In this article, we will learn how to create GST Rate Finder GUI application using Tkinter, with a step-by-step guide. To create a Tki
3 min read
Create Copy-Move GUI using Tkinter in Python
Everyone reading this post is well aware of the importance of Copying the file or moving the file from one specific location to another. In this post, we have tried to explain not only the program but added some exciting pieces of Interface. Up to now, many of you may get about what we are talking about. Yes, you are right, We are going to use "Tki
4 min read
Python - English (Latin) to Hindi (Devanagiri) text convertor GUI using Tkinter
Prerequisites : Introduction to tkinter | Text transliteration from English to Indian languages – Using indic-transliterationPython offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python
4 min read
Standard GUI Unit Converter using Tkinter in Python
Prerequisites: Introduction to tkinter, Introduction to webbrowser In this article, we will learn how to create a standard converter using tkinter. Now we are going to create an introduction window that displays loading bar, welcome text, and user's social media profile links so that when he/she shares his code with some others, they can contact th
12 min read
GUI chat application using Tkinter in Python
Chatbots are computer program that allows user to interact using input methods. The Application of chatbots is to interact with customers in big enterprises or companies and resolve their queries. Chatbots are mainly built for answering standard FAQs. The benefit of this type of system is that customer is no longer required to follow the same tradi
7 min read
Text to speech GUI convertor using Tkinter in Python
Prerequisite: Introduction to Tkinter Tkinter is the standard GUI library for Python. Python when combined with tkinter provides a fast and easy way to create GUI applications.By this library we can make a compelling choice for building GUI applications in Python, especially for applications where a modern sheen is unnecessary, and the top priority
3 min read
Create a GUI to check Domain Availability using Tkinter
There might be a case where a user wants to create a website and having certain ideas for the website's name but is struck on their availability. So let's develop a GUI that will check for domain availability. We will use the Python-whois module to get information about the website. It's able to extract data for all the popular TLDs (com, org, net,
2 min read
Create a GUI to Get Domain Information Using Tkinter
Prerequisites: Python GUI – tkinter Domain information is very important for every user. It contains information like Name, organization, State, city, Ip address, emails, server name, etc. In this article, we will write code for getting domain information and bind it with GUI Application. We will use the Python-whois module to get information about
2 min read
Tic Tac Toe game with GUI using tkinter in Python
Tic-tac-toe (American English), noughts and crosses (British English), or Xs and Os is a paper-and-pencil game for two players, X and O, who take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row is the winner. tkinter Python library is used to create the GUI.
15+ min read
Build GUI Application for Guess Indian State using Tkinter Python
In this article, you will learn to make a GUI game in Python, in which we will be shown a map of Indian states and an input prompt were in the prompt, the user has to enter a state name of India. If the user guessed it correctly, the name would hover over its location on the map. You can also see the score as the title of the input prompt window. M
8 min read
Create First GUI Application using Python-Tkinter
We are now stepping into making applications with graphical elements, we will learn how to make cool apps and focus more on its GUI(Graphical User Interface) using Tkinter. What is Tkinter?Tkinter is a Python Package for creating GUI applications. Python has a lot of GUI frameworks, but Tkinter is the only framework that’s built into the Python sta
12 min read