Skip to content

Instantly share code, notes, and snippets.

@ronsims2
Created April 1, 2015 20:46
Show Gist options
  • Save ronsims2/56c0b5ff65564f233c3e to your computer and use it in GitHub Desktop.
Save ronsims2/56c0b5ff65564f233c3e to your computer and use it in GitHub Desktop.
import random
from Tkinter import *
import tkMessageBox
class Application(Frame):
def show_handicap(self):
grossScore = self.grossScore.get()
courseRating = self.courseRating.get()
courseSlope = self.courseSlope.get()
def checkNum(val):
try:
float(val)
return True
except error:
return False
if (checkNum(grossScore) and checkNum(courseRating) and checkNum(courseSlope)):
#handicap formula
handiCap = (((float(grossScore) - float(courseRating)) * 113) / float(courseSlope)) * .96
handiCap = int(handiCap)
msg = "Gross Score: " + str(grossScore) + \
"\nCourse Rating: " + str(courseRating) + \
"\nCourse Slope: " + str(courseSlope)
handiMsg = "Your handicap is: " + str(handiCap)
ttl = "HandiCalc"
tkMessageBox.showinfo(ttl, handiMsg)
def createWidgets(self):
self.columnconfigure(0, pad=4)
self.columnconfigure(1, pad=4)
self.rowconfigure(0, pad=4)
self.rowconfigure(1, pad=4)
self.rowconfigure(2, pad=4)
self.rowconfigure(3, pad=4)
self.rowconfigure(4, pad=4)
ttl = "Sims Handicap Calculator"
self.panel = Label(self)
self.panel["text"] = ttl
self.panel.grid(row=0, column=0, columnspan=2)
gstext = "Gross Score"
self.gsLabel = Label(self)
self.gsLabel["text"] = gstext
self.gsLabel.grid(row=1, column=0)
self.grossScore = Entry(self)
self.grossScore.grid(row=1, column=1)
#self.grossScore.pack({"side": "left"})
crtext = "Course Rating"
self.crLabel = Label(self)
self.crLabel["text"] = crtext
self.crLabel.grid(row=2, column=0)
self.courseRating = Entry(self)
self.courseRating.grid(row=2, column=1)
#self.courseRating.pack({"side": "left"})
cstext = "Course Slope"
self.csLabel = Label(self)
self.csLabel["text"] = cstext
self.csLabel.grid(row=3, column=0)
self.courseSlope = Entry(self)
self.courseSlope.grid(row=3, column=1)
self.calc = Button(self)
self.calc["text"] = "Calculate Handicap"
#self.calc["height"] = 80
self.calc.grid(row=4, column=1, columnspan=1)
self.calc["command"] = self.show_handicap
#self.calc.pack({"side": "left"})
def __init__(self, master = None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
root = Tk()
app = Application(master = root)
app.master.title("Ron's first Mac App")
app.master.maxsize(400, 300)
app.master.minsize(400, 300)
app.mainloop()
#root.destroy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment