This is the code that I have so far. Towards the end I'm having troubles figuring out how to make a popup window saying "Grade is [A]", once the student ID is entered. I also don't know how to create a popup window saying "Student ID not found" if an incorrect ID is entered. I put asterisks by the part I'm having problems with. Thank you!
from Tkinter import *
import tkFont
import tkMessageBox
students = {}
class studentDB :
def __init__(self) : # Constructor
# Sets attributes "studentID", "lastName", "firstName"; sets attribute "scores" as empty list
global students
students[1000] = student(1000, 'abc', (92, 95, 97))
students[1001] = student(1001, 'def', (84, 91, 77))
class student :
def __init__(self, sid, passwd, scoreList) : # Constructor
# Sets attributes "studentID", "lastName", "firstName"; sets attribute "scores" as empty list
self.studentID = sid
self.passwd = passwd
self.scores = scoreList
def getPassword(self) : # Returns the student ID
# Returns attribute "studentID"
return(self.passwd)
def computeAverage(self) : # Computes & returns the total score
# Computes & returns totalScore of list attribute "scores"
totalScore = 0
for val in self.scores :
totalScore = totalScore + val
return(totalScore/float(len(self.scores)))
def getGrade(score) :
if (score >= 90) :
return 'A'
elif (score >= 80) :
return 'B'
elif (score >= 70) :
return 'C'
elif (score >= 60) :
return 'D'
else :
return 'F'
class myApp :
def __init__(self, top) :
# Creates a window with:
# Label and text box for "Student's ID";
# Button labeled "Get Grade" to get the grade for the student; and
# Button labeled "Quit" to quit the application
# You must write the rest of the myApp constructor, here.
self.root = top
self.bframe = Frame(self.root) # Create a container Frame at the bottom
self.bframe.pack(side=BOTTOM)
self.xlabel = Label(self.root, text="Student ID") # Create Label
self.xlabel.pack(side=LEFT)
self.xentry = Entry(self.root, bd=5) # Create Entry box
self.xentry.pack(side=LEFT)
self.xentry.focus_set() # Set focus in Entry box
self.xopen = Button(self.root, text="Get Grade", command=self.showGrade) # Create open Button
self.xopen.pack(side=LEFT)
self.xquit = Button(self.bframe, text="Quit", command=self.quitit) # Create quit Button
self.xquit.pack(side=BOTTOM)
def showGrade(self) :
# Creates either:
# Warning message if SID is not found or
# Information messaged with grade
global students
# You must write the rest of the showGrade method, here.
**sid = self.xentry.get()
if
import tkMessageBox**
def quitit(self) :
# Handler for Quit button click
self.root.destroy()
return
# End of myApp class
studentDB()
top = Tk()
app = myApp(top)
top.mainloop()