Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1
self.score3.grid(row=4, column=1)
self.average.grid(row=5, column=1)
self.button1 = Button(self, text="Calculate Average",
command=self.calculate)
self.button1.grid(row=6, column=0)
self.button2 = Button(self, text='Clear result',
command=self.clear)
self.button2.grid(row=6, column=1)
self.score1.focus_set()
root.config(menu=menubar)
def calculate(self):
"""Calculate and display the average"""
numScore1 = int(self.score1.get())
numScore2 = int(self.score2.get())
numScore3 = int(self.score3.get())
total = numScore1 + numScore2 + numScore3
average = total / 3
strAverage = "{0:.2f}".format(average)
self.average.insert(0, strAverage)

def clear(self):
"""Clear the Entry forms"""
self.score1.delete(0,END)
self.score2.delete(0,END)
self.score3.delete(0,END)
self.average.delete(0,END)
self.score1.focus_set()

root = Tk()
root.title('Bowling Average Calculator')
root.geometry('500x200')
app = Application(root)
app.mainloop()


  1. Save the script1809.py file.

  2. Run the script1809.py program from an LXTerminal session in your desktop.
    A window like the one shown in Figure 18.4 should appear.

Free download pdf