"""The CounterButton module contains the class that builds a customized
   controller for the each button of the GUI.
"""
from Tkinter import *

class Control(object) :
    """Control constructs a customized controller that remembers the
       number of times the corresponding button is pressed.
       The controller holds the event-handling function.
       It also remembers these attributes:
          mybutton - the button that this controller is connected to
          mycount - an int, how many times the button is pressed
    """

    def __init__(self, b) :
        """init  constructs the controller

           parameters: self - the new controller object we are constructing
                       b - the button controlled by this controller
        """
        # create these two variables in the controller's namespace:
        self.mybutton = b
        self.mycount = 0

    def handle(self) :
        """This is the event handler for the button."""
        global total_presses
        # update  mycount  in this controller's namespace:
        self.mycount = self.mycount + 1
        # reconfigure the button controlled by this controller:
        self.mybutton.configure(text = str(self.mycount))