I'm using cs1graphics module. I'm like really stuck as to what do next. What I'm attempting to do is create a handler that counts the number of clicks on the canvas and when the exit button is clicked it exits the canvas. I originally added the exit canvas outside of the class before I realized that my class had no attribute to the exit button so I added the exit button in the class but it doesnt come out, nor does my program count the clicks. I've read countlessly on the topic of event handling and I am seriously just stuck. I really don't need anyone to do it for me, I just need to understand what it is that I'm doing wrong. Its driving me crazy!
from cs1graphics import* class MouseHandler(EventHandler): def __init__ (self, textObj): EventHandler.__init__(self) self._text = textObj self._count = 0 self._text.setMessage(str(self._count)) def handle(self, event): if event.getDescription() == 'mouse click': self._counter >= 1 self._text.setMessage(str(self._count)) class ExitButtonHandler(EventHandler): def __init__(self, message='', centerPt=None): EventHandler.__init__(self) self._exitButton=Rectangle(60, 30) self._exitButton.setFillColor('grey') self._message='Exit' self.centerPt=Point(600,555) def handle(self, event): if event.getDescription() == 'mouse click': if event.getTrigger()in self._exitButton: exit() def main(): paper=Canvas(700, 600, 'white', 'Number of clicks') text1=Text('Times clicked:', 12, Point(140, 550)) paper.add(text1) text2=Text('', 12, Point(300, 550)) paper.add(text2) counter=MouseHandler(text2) paper.addHandler(counter) exitEvent = ExitButtonHandler() paper.addHandler(exitEvent) main()