Search Here

Create Ecat Aggregate Calculator using Python and Tkinter

 In this article, you will learn how to create Ecat Aggregate Calculator using python and Tkinter. To design the application interface (GUI) we will use the grid layout. If you are not familiar with layouts, check out Geometry Manager in Tkinter.

Create Ecat Aggregate Calculator in Tkinter

Create Ecat Aggregate Calculator using Python and Tkinter

Tkinter is the most popular and powerful way to create GUI applications. In this tutorial, I am going to show you how to use Grid Layout Manager to create an Ecat Aggregate Calculator. You will also learn the implementation of Grid, Labels, Entry, and Button.

Following are the main key points to build this application.

Import Tkinter Library

To create a GUI application using Python programming language we will use the Tkinter library or module in our code. For this purpose, we have to import this library using the "import module_name" (import tkinter as tk) command.

Create or Define Container

Every GUI application consists of UI elements or widgets like (Frame, PhotoImage, Grid, Labels, Entry, and Button). To place these UI elements or widgets we need a container, and this container is called Window or Root Window. To create a Window we need the Geometry method, that defines the root window of the application.

Design UI Elements

After creating container, we will design our application interface. This will include Labels, PhotoImage, Entry and Button. And to layout them we will use Grid layout manager.


Widget Description
Label To display text in our application we will use label widget.
Entry Entry element or widget will create an input field, in which user will enter some value.
PhotoImage To display images or photos.
Button This will create a button, on button click we call a method which calculate Ecat Aggregate.

Features of the Ecat Aggregate Calculator
  • If you click on "Check Aggregate" button without filling form values, app will give warning message.
  • If you have no values in some of the input fields, app will give warning message.
  • If you enter string values instead of integer, app will give warning message.
  • On clicking of "Clear" button, app will reset all the input fields.


import tkinter as tk
from tkinter import messagebox
from tkinter import *
# reset input values or entry
def remove():
matric_total_entry.delete(0, END)
matric_obtained_entry.delete(0, END)
inter_obtained_entry.delete(0, END)
inter_total_entry.delete(0, END)
ecat_marks_entry.delete(0, END)
messagebox.showinfo("information", "data cleared successfully")
# command after the button click
def getvals():
global total_agregate
global label_window
global label_window1
# getting the marks from the entry widget
marks_matric_total = matric_total_entry.get()
marks_matric_obtained = matric_obtained_entry.get()
marks_inter_total = inter_total_entry.get()
marks_inter_obtained = inter_obtained_entry.get()
marks_ecat_obtained = ecat_marks_entry.get()
# validaations for the ecat obtained
if marks_ecat_obtained == "" and marks_inter_obtained == "" and marks_inter_total == "" and marks_matric_total == "" and marks_matric_obtained == "":
messagebox.showinfo('Error', 'Fil the form carefully')
else:
if marks_ecat_obtained == "":
messagebox.showinfo('Error', 'Put ecat obtained marks')
elif marks_matric_total == "":
messagebox.showinfo('Error', 'Enter matric total marks')
elif marks_matric_obtained == "":
messagebox.showinfo('Error', 'Enter matric obtained marks')
elif marks_inter_total == "":
messagebox.showinfo('Error', 'Put inter total marks')
elif marks_inter_obtained == "":
messagebox.showinfo('Error', 'Put Intermediate obtained marks')
else:
if not marks_ecat_obtained.isdigit():
messagebox.showinfo('Error', 'Enter only number in the " Ecat obtained marks"')
elif not marks_matric_total.isdigit():
messagebox.showinfo('Error', 'Enter only number in the "Matric total marks"')
elif not marks_matric_obtained.isdigit():
messagebox.showinfo('Error', 'Enter only number in the "Matric obtained marks"')
elif not marks_inter_total.isdigit():
messagebox.showinfo('Error', 'Enter only number in the "Intermidate total marks"')
elif not marks_inter_obtained.isdigit():
messagebox.showinfo('Error', 'Enter only number in the "Intermediate obtained marks"')
else:
if float(marks_ecat_obtained) > 400:
messagebox.showinfo('Error', "Enter ecat marks less than 400")
elif float(marks_matric_obtained) > float(marks_matric_total):
messagebox.showinfo('Error', 'Matric obtained marks should be less or equal to total marks')
elif float(marks_inter_obtained) > float(marks_inter_total):
messagebox.showinfo('Error', "inter obtained marks should be less than or equal to total marks")
else:
# adding extra 20 marks in the matric obtained by getting the value form check box
if (check_var1.get() == 1):
marks_matric_obtained = float(marks_matric_obtained) + 20
# calculating the aggregate individualy
matric_agregate = (float(marks_matric_obtained) / float(marks_matric_total)) * 25
inter_agregate = (float(marks_inter_obtained) / int(marks_inter_total)) * 45
ecat_agregate = (float(marks_ecat_obtained) / 400) * 30
# total aggregate by adding the inter ,matric and ecat marks
total_agregate = float(matric_agregate + inter_agregate + ecat_agregate)
# show total aggregte in label of the window
lbl_aggregate = tk.Label(app, text=total_agregate, font=("helvatica", 10, "bold"), fg='#0a074f')
lbl_aggregate.grid(column=0, row=9, columnspan=9)
# checking the aggregate for each departments
if total_agregate >= 91 and total_agregate <= 100:
text="You are eligible for Electrical Engineering"
elif total_agregate >= 81 and total_agregate < 91:
text="You are eligible for Mechanical Engineering"
elif total_agregate >= 71 and total_agregate < 81:
text="You are eligible for Software Engineering"
elif total_agregate >= 61 and total_agregate < 71:
text="You are eligible for Computer Engineering"
elif total_agregate >= 51 and total_agregate < 61:
text="You are eligible for Civil Engineering"
elif total_agregate >= 1 and total_agregate < 51:
text="Your aggregate is very low you are not eligible for the admission"
else:
text="Invalid input "
label_message = tk.Label(app, text=text, font=("helvatica", 10, "bold"),fg='#31680E')
label_message.grid(column=0, row=10, columnspan=9)
label_message.destroy()
# make the label clear when the second time buttonn is clicked
app = tk.Tk()
# this is title
app.title('Aggregate Calculator')
# screen size
app.geometry("600x500")
# top most label
lbl_heading = tk.Label(app, text="Aggregate Calculator for Admission", font=("helvatica", 20, "bold"))
lbl_heading.grid(column=0, row=0, columnspan=9)
# picture at the top
logo = tk.PhotoImage(file='download.png')
lbl_Logo = tk.Label(app, image=logo)
lbl_Logo.grid(row=0, column=10, rowspan=2)
# labels in the window which is positoned by grid layout
lbl_matric_total = tk.Label(app, text="Matric total marks", font=("helvatica", 10, 'bold'), justify=tk.RIGHT,anchor="e")
lbl_matric_total.grid(column=0, row=3, pady=5, sticky=tk.E)
lbl_matric_obtained = tk.Label(app,text="Matric obtained marks", font=("helvatica", 10, 'bold'), justify=tk.RIGHT,anchor="e")
lbl_matric_obtained.grid(column=0, row=4, ipadx=5, pady=5, sticky=tk.E)
lbl_inter_total = tk.Label(app,text="Intermediate total marks", font=("helvatica", 10, 'bold'), justify=tk.RIGHT,anchor="e")
lbl_inter_total.grid(column=0, row=5, pady=5, sticky=tk.E)
lbl_inter_obtained = tk.Label(app,text="Intermediate obtained marks", font=("helvatica", 10, 'bold'), justify=tk.RIGHT,anchor="e")
lbl_inter_obtained.grid(column=0, row=6, pady=5, sticky=tk.E)
lbl_ecat_obtained = tk.Label(app,text="Ecat obtained marks", font=("helvatica", 10, 'bold'), justify=tk.RIGHT, anchor="e")
lbl_ecat_obtained.grid(column=0, row=2, pady=5, sticky=tk.E)
# entry widget that takes input from the user and positoning the entry widget by using grid layout
matric_total_entry = tk.Entry(app, width=30)
matric_total_entry.grid(column=1, row=3, padx=10, pady=5)
matric_obtained_entry = tk.Entry(app, width=30)
matric_obtained_entry.grid(column=1, row=4, padx=10, pady=5)
inter_total_entry = tk.Entry(app, width=30)
inter_total_entry.grid(column=1, row=5, padx=10, pady=5)
inter_obtained_entry = tk.Entry(app, width=30)
inter_obtained_entry.grid(column=1, row=6, padx=10, pady=5)
ecat_marks_entry = tk.Entry(app, width=30)
ecat_marks_entry.grid(column=1, row=2, padx=10, pady=5)
# check box to check Hafiz e Quran
check_var1 = tk.IntVar()
checkbox = tk.Checkbutton(app, text='Hafiz e quran', variable=check_var1, onvalue=1, offvalue=0, justify=tk.LEFT,
anchor="w")
checkbox.grid(row=7, column=1, sticky=tk.W, padx=10)
# submit button that perform some action on click
resultButton = tk.Button(app, text='Check Aggregate', command=getvals)
resultButton.grid(row=8, column=0, pady=5, columnspan=2)
# clear button
ClearButton = tk.Button(app, text='Clear', command=remove)
ClearButton.grid(row=8, column=1, pady=5, columnspan=2, padx=5)
# window is not resizable
app.resizable(False, False)
app.mainloop()

Post a Comment

0 Comments