Created
February 28, 2018 13:39
-
-
Save bmontana/d91c3a07d71edb7e39fef44d5e36d6f1 to your computer and use it in GitHub Desktop.
Graphics program to roll a pair of dice. Uses custom widgets Button and DieView.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# roller.py | |
# Graphics program to roll a pair of dice. Uses custom widgets | |
# Button and DieView. | |
from random import randrange | |
from graphics import GraphWin, Point | |
from button import Button | |
from dieview import DieView | |
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() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment