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 = CButton(win, Point(5, 4.5), 1.5, "Roll Dice") rollButton.activate() quitButton = CButton(win, Point(5, 1), 1, "Quit") # Event loop pt = win.getMouse() while not quitButton.clicked(pt): if rollButton.clicked(pt): 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(): # create the application window win = GraphWin("Dice Roller", ) win.setCoords(0, 0, 10, 10) win.setBackground("green2") # draw the interface widgets b1 = Button(win, Point(4, 2), 3, 2, "Roll") b2 = Button(win, Point(8, 2), 3, 2, "Quit") d1 = DieView(win, Point(3, 6), 3) d2 = DieView(win, Point(7, 6), 3) # event loop while True: if b1.clicked(win.getMouse()): d1.setValue(MSdie().setValue()) d2.setValue(MSdie().setValue()) elif b2.clicked(win.getMouse()): return False # close the window win.close()
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): 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(): # create the application window win = GraphWin("Dice Roller", WINDOW_WIDTH, WINDOW_HEIGHT) win.setBackground("black") # draw the interface widgets centerPoint = Point(WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2) quit = Button(win, Point(WINDOW_WIDTH - 75, WINDOW_HEIGHT - 50), 75, 50, 'Quit') quit.activate() roll = Button(win, Point(WINDOW_WIDTH - 150, WINDOW_HEIGHT - 50), 75, 50, 'Roll') roll.activate() die1 = DieView(win, Point(WINDOW_WIDTH / 2 - 50, WINDOW_HEIGHT / 2), 50) die2 = DieView(win, Point(WINDOW_WIDTH / 2 + 50, WINDOW_HEIGHT / 2), 50) # event loop run = True while run: clickPoint = win.getMouse() if (roll.clicked(clickPoint)): die1.setValue(randrange(1, 7)) die2.setValue(randrange(1, 7)) run = not quit.clicked(clickPoint) # close the window win.close()
def main(): # Create the application window win = GraphWin('Dice Roller', 500, 500) win.setCoords(0, 0, 10, 10) win.setBackground(color_rgb(0, 75, 0)) # 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), 1.25, 'Roll Dice') rollButton.activate() quitButton = Button(win, Point(5, 1), 1, 'Quit') # Event loop pt = win.getMouse() while not quitButton.clicked(pt): if rollButton.clicked(pt): value1 = randrange(1, 7) #die1.setColor(color_rgb(randrange(255), randrange(255), randrange(255))) die1.setValue(value1) value2 = randrange(1, 7) die2.setColor( color_rgb(randrange(255), randrange(255), randrange(255))) die2.setValue(value2) quitButton.activate() pt = win.getMouse() # Exit Program win.close()
def main(): # Create the application window win = GraphWin('Dice Roller', 500, 500) win.setCoords(0, 0, 10, 10) win.setBackground(color_rgb(0,75,0)) # 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), 1.25, 'Roll Dice') rollButton.activate() quitButton = Button(win, Point(5,1), 1, 'Quit') # Event loop pt = win.getMouse() while not quitButton.clicked(pt): if rollButton.clicked(pt): value1 = randrange(1,7) #die1.setColor(color_rgb(randrange(255), randrange(255), randrange(255))) die1.setValue(value1) value2 = randrange(1,7) die2.setColor(color_rgb(randrange(255), randrange(255), randrange(255))) die2.setValue(value2) quitButton.activate() pt = win.getMouse() # Exit Program win.close()
def setValue(self, value): """ Overrides DieView.setValue(), saving value locally first, then calling DieView.setValue() :param value: int -> value to set for die """ self.value = value # remember this value DieView.setValue(self, value) # call setValue from parent class
def main(): # create the application window win = GraphWin("Dice Roller") win.setCoords(0,0,10,10) win.setBackground("gray") # 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): # re-rolling value and pip color of die1 value1 = randrange(1, 7) color = color_rgb(randrange(0,256), randrange(0,256), randrange(0,256)) die1.setValue(value1) die1.setColor(color) # re-rolling value and pip color of die2 value2 = randrange(1, 7) color = color_rgb(randrange(0,256), randrange(0,256), randrange(0,256)) die2.setValue(value2) die2.setColor(color) quitButton.activate() pt = win.getMouse() # close up shop win.close()
def main(): win = GraphWin("Dice Roller") win.setCoords(0, 0, 10, 10) win.setBackground("green2") 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") pt = win.getMouse() while not quitButton.clicked(pt): if rollButton.clicked(pt): value1 = randrange(1, 7) die1.setValue(value1) value2 = randrange(1, 7) die2.setValue(value2) quitButton.activate() pt = win.getMouse() win.close()
def main(): win = GraphWin("Dice Roller") win.setCoords(0, 0, 10, 10) win.setBackground("green2") 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") p = win.getMouse() while not quitButton.clickedab(p): if rollButton.clickedab(p): value1 = randrange(1, 7) die1.setValue(value1) value2 = randrange(1, 7) die2.setValue(value2) quitButton.activate() pt = win.getMouse() win.close()
def main(): # create the application window win = GraphWin( "Dice Roller" ) # Constructs a new graphics window for drawing on the screen. (title, width, height) win.setCoords( 0, 0, 10, 10 ) # Sets the coordinate system of the window in the format (xll, yll, xur, yur) # The lower-left corner is (xll, yll) and the upper-right corner is (xur, yur) win.setBackground("red2") # Sets the window background to the given color # 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( ) # Pauses for the user to click a mouse in the window and returns where the mouse was # clicked as a Point object. while not quitButton.clicked(pt): if rollButton.clicked(pt): value1 = randrange(1, 7) die1.setValue(value1) value2 = randrange(1, 7) die2.setValue(value2) quitButton.activate() pt = win.getMouse() # close win.close() # Closes the on-screen window
def main(): # create the application window win = GraphWin("Dice Roller", ) win.setCoords(0, 0, 12, 12) win.setBackground("green") roll_btn = Button(win, Point(3, 2), 3, 3, "Roll") quit_btn = Button(win, Point(7, 2), 3, 3, "Quit") d1 = DieView(win, Point(3, 6), 3) d2 = DieView(win, Point(7, 6), 3) # while True: if roll_btn.clicked(win.getMouse()): d1.setValue(MSdie(6).roll()) d2.setValue(MSdie(6).roll()) elif quit_btn.clicked(win.getMouse()): return False # close the window win.close()
class App(): def __init__(self): self.win = g.GraphWin(title="Dice Game", width=500, height=500) self.dwidget1 = DieView(self.win, center=g.Point(40, 40), size=40) self.dwidget2 = DieView(self.win, center=g.Point(90, 40), size=40) self.dwidget3 = DieView(self.win, center=g.Point(40, 100), size=40) self.dwidget4 = DieView(self.win, center=g.Point(90, 100), size=40) self.dwidget5 = DieView(self.win, center=g.Point(40, 160), size=40) # self.button = g.Rectangle(g.Point(10,200),g.Point(90,230)) # self.button.setFill('green') self.win.bind("<Button-1>", self.reroll) def rollDice(self): self.dwidget1.setValue(random.randint(1, 6)) self.dwidget2.setValue(random.randint(1, 6)) self.dwidget3.setValue(random.randint(1, 6)) self.dwidget4.setValue(random.randint(1, 6)) self.dwidget5.setValue(random.randint(1, 6)) def reroll(self, event): self.dwidget1.setValue(random.randint(1, 6)) self.dwidget2.setValue(random.randint(1, 6)) self.dwidget3.setValue(random.randint(1, 6)) self.dwidget4.setValue(random.randint(1, 6)) self.dwidget5.setValue(random.randint(1, 6)) def run(self): self.rollDice() self.win.getMouse() print('running') self.win.close()
def setValue(self, value): self.value = value # remember this value DieView.setValue(self, value) # call setValue from parent class
def setValue(self, value): self.value = value DieView.setValue(self, value)