''' voting.py - click a rectangle to vote for it @author - spc ''' from graphics import * def main(): # setup window = GraphWin("Voting", 380, 120) window.setBackground('blue3') cand1 = Rectangle(Point(10, 10), Point(80, 80)) cand1.setFill('yellow') cand1.draw(window) cand2 = Rectangle(Point(260, 10), Point(330, 80)) cand2.setFill('purple') cand2.draw(window) # here's where the voting starts maybe = window.getMouse() if ((maybe.getX() > 10 and maybe.getX() < 80) and (maybe.getY() > 10 and maybe.getY() < 80)): print('Voted for Yellow rect.') elif ((maybe.getX() > 260 and maybe.getX() < 330) and (maybe.getY() > 10 and maybe.getY() < 80)): print('Voted for Purple rect.') else: print('Click was in no rect') window.getMouse() window.close() if __name__ == "__main__": main()