import tkinter

# class that will hold all "state" information used by program
class StateVars:
    def __init__(self):
        self.counter = 0

    def getCounter(self):
        return self.counter
    
    def updateCounter(self, changeAmount):
        self.counter = self.counter + changeAmount

# "callback" functions
def increaseBy1():
    stateVars.updateCounter(1)
    updateCountLabel()

def decreaseBy1():
    if stateVars.getCounter() > 0:
        stateVars.updateCounter(-1)
    updateCountLabel()

# "helper" function used by both callbacks
def updateCountLabel():
    countLabel.configure(text="Count: {}".format(stateVars.getCounter()))


# window, widget and layout specifications
mainWindow = tkinter.Tk()

# frame to hold two side-by-side widgets, the + and - buttons
topFrame = tkinter.Frame(mainWindow)
topFrame.pack()

increaseButton = tkinter.Button(topFrame, text="+", command=increaseBy1)
increaseButton.pack(side=tkinter.LEFT)
decreaseButton = tkinter.Button(topFrame, text="-", command=decreaseBy1)
decreaseButton.pack()

# show the current count in a label below the buttons
countLabel = tkinter.Label(mainWindow, text="Count: 0")
countLabel.pack()

# GO!
#
stateVars = StateVars() 
mainWindow.mainloop()


