Question 4. (15 points) Consider the following GUI Tkinter program.
--- FinalTestQuestion.py GUI Question Code ---
from Tkinter import *
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.initUI()
def initUI(self):
self.master.title("Final Question Example")
self.name = StringVar()
self.age = IntVar()
self.name.set("Enter name here")
self.age.set(0)
self.displaylabelText = StringVar()
self.displaylabelText.set("\n\n\n\n")
self.createWidgets()
def createWidgets(self):
nameEntry = Entry(self, takefocus=1, textvariable = self.name, width = 40)
nameEntry.grid(row=0, sticky=E+W)
ageEntry = Entry(self, takefocus=1, textvariable = self.age, width = 20)
ageEntry.grid(row=1, sticky=W)
displayLabel = Label(self, textvariable=self.displaylabelText,
justify=LEFT)
displayLabel.grid(row=2, sticky=N+S+E+W)
doneButton = Button(self, text="Done", command=self.myEvent)
doneButton.grid(row=3, sticky=S)
def myEvent(self):
print "Button Pressed"
self.displaylabelText.set("Name: " + self.name.get() +
"\nage: " + str(self.age.get()) + "\n\n")
def main():
application = Application()
application.mainloop()
a) What would the window look like when the application starts to run?
Input fields to enter name and age and a done button to click once information is entered
b) After typing your name and age into the Entry widgets and then clicked on the "Done" button, what
would the window look like?