def main(): # create the application window win = GraphWin("Dice Roller") win.setCoords(0, 0, 10, 10) win.setBackground("green2") # Draw the interface widgets die1 = DieView(win, Point(3, 7), 2) die2 = DieView(win, Point(7, 7), 2) rollButton = Button(win, Point(5, 4.5), 6, 1, "Roll Dice") rollButton.activate() quitButton = Button(win, Point(5, 1), 2, 1, "Quit") # Event loop pt = win.getMouse() while not quitButton.clicked(pt): if rollButton.clicked(pt): # pick a random color color = color_rgb(randrange(256), randrange(256), randrange(256)) # set dice to have new color die1.setColor(color) die2.setColor(color) value1 = randrange(1, 7) die1.setValue(value1) value2 = randrange(1, 7) die2.setValue(value2) quitButton.activate() pt = win.getMouse() # close up shop win.close()
def main(): # Set up interface win = GraphWin("Extended Three Button Monte", 350, 350) win.setCoords(.5, -2, 3.5, 3) b1 = Button(win, Point(1, 2), .75, 1, "Door 1") b1.activate() b2 = Button(win, Point(2, 2), .75, 1, "Door 2") b2.activate() b3 = Button(win, Point(3, 2), .75, 1, "Door 3") b3.activate() again = Button(win, Point(1.25, 0), 1, .75, "Play Again") quit = Button(win, Point(2.75, 0), 1, .75, "Quit") mess = Text(Point(2, .75), "Guess a door") mess.setStyle("bold") mess.draw(win) scoreBox = Text(Point(2, -1), "") scoreBox.draw(win) playAgain = True hits = 0 misses = 0 while playAgain: mess.setText("Guess a door") pick = getDoorPick(win, b1, b2, b3) hits, misses = updateScore(pick, mess, scoreBox, hits, misses) playAgain = quitOrPlay(win, quit, again) win.close()
def main(): win = GraphWin("Three Button Monte", 350, 100) win.setCoords(.5, 0, 3.5, 3) b1 = Button(win, Point(1, 2), .75, 1, "Door 1") b1.activate() b2 = Button(win, Point(2, 2), .75, 1, "Door 2") b2.activate() b3 = Button(win, Point(3, 2), .75, 1, "Door 3") b3.activate() mess = Text(Point(2, .75), "Guess a door.") mess.setStyle("bold") mess.draw(win) secret = randrange(1, 4) choice = None while choice == None: pt = win.getMouse() for button in [b1, b2, b3]: if button.clicked(pt): choice = button choiceNum = int(choice.getLabel()[-1]) if choiceNum == secret: mess.setText("You win!") else: mess.setText("You lose. The answer was door {0}.".format(secret)) win.getMouse() win.close()