In: Computer Science
Python
Using tkinter, create a GUI interface which accepts input of a GPA.
If the GPA is >= 3.5, display 'Dean’s List'
If the GPA is < 2.0, display 'Probation’
If the GPA is < 3.5 and >= 2.0, display 'Regular Standing'
Run one test case for each case above and save the output.
PLEASE NOTE : FEEL FREE TO ASK ANY DOUBTS by COMMENTING
Language : Python
:::::::::::::::::::::::::::::::::::::::::::: CODE ::::::::::::::::::::::::::::::::::::::::
from tkinter import *
# Function to set Result Label text
def callback(sv,label):
# try - except block to avoid errors
try:
# if entry value is null, set label text as belo
if(sv.get().strip()==""):
label.set("Enter GPA")
return
# if entry value is not null, conver value to float
gpa = float(sv.get())
# to store result text
result = ""
# assign result text as rules
if(gpa>=3.5):
result = "Dean’s List"
elif(gpa<3.5 and gpa>=2.0):
result = "Probation"
else:
result = "Regular Standing"
# set label text to result value
label.set(result)
except ValueError:
# if any value error occured, set label as Invalid gpa
label.set("Invalid GPA")
# main function
def main():
# create tkinter object
root = Tk()
# set window title, size of width 300 and heigth 200
root.title("GPA")
root.geometry("300x200")
# set window to non resizable
root.resizable(0,0)
# creating StringVar for window. one for entry, one for result
label
sv = StringVar()
result = StringVar(root)
# trace StringVar to call callback with both StringVar
above
# this trace changes in Entry of GPA value
sv.trace("w", lambda name, index, mode, sv=sv:
callback(sv,result))
# create label at x-axis 10 and y-axis 20
Label(root,text="Enter GPA : ",font=(12)).place(x=10,y=20)
# create entry box at x-axis 100 and y-axis 20 and set
textvariable to StringVar "sv"
Entry(root, textvariable=sv,font=(12)).place(x=100,y=20)
# create label for result label, at x-axis 150 and y-axis 100
and set anchor to center
# and set textvariable to StringVar "result"
Label(root,textvariable=result,font=(12)).place(x=150,y=100,anchor="center")
# run window
root.mainloop()
# Call above main method
main()
:::::::::::::::::::::::::::::::::::::::::::: OUTPUT
::::::::::::::::::::::::::::::::::::::::
No GPA Entered/ Only whitespaces
Entered Value for Regular Standing
Entered Value for Probation
Entered Value for Dean's List
Entered Invalid Value/Characters
:::::::::::::::::::::::::::::::::::::: CODE in EDITOR ::::::::::::::::::::::::::::::::::
_________________________________________________________________
Dear Friend, Feel Free to Ask Any Doubts by Commenting. ASAP i'll respond when i'm available.
I'm on a critical Situation. Please Do Not Forget To Give A Thumbs UP +1. It will Helps me A Lot.
Thank YOU :-)