Esempio n. 1
0
def main():
    win = GraphWin("House", 600, 600)
    win.setCoords(0,0,600,600)
    Text(Point(300,10),"5 Click House").draw(win)
    # Draw the main house
    p1 = win.getMouse()
    p2 = win.getMouse()
    Rectangle(p1, p2).draw(win)

    # Draw the door
    con = (abs(p1.x) - (p2.x)) / 5
    p3 = win.getMouse()
    d1 = Point(p3.x + con / 2, p3.y)
    d2 = Point(p3.x - con / 2, p1.y)
    Rectangle(d1, d2).draw(win)

    # Draw the window
    p4 = win.getMouse()
    w1 = Point(p4.x - con / 4, p4.y + con / 4)
    w2 = Point(p4.x + con / 4, p4.y - con / 4)
    Rectangle(w1, w2).draw(win)

    p5 = win.getMouse()
    Polygon(p2, Point(p1.x, p2.y), p5).draw(win)

    Text(Point(300,590),"I hoped you liked my house!!").draw(win)
    time.sleep(10) # sleep the thread for 10 seconds
Esempio n. 2
0
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()
Esempio n. 3
0
def eye_picker():
    """
    8. The pract06.py file contains an incomplete draw_coloured_eye() function
    for which the graphics window, centre point, radius and eye colour (a
    string) are given as parameters. Complete the draw_coloured_eye() function
    so that it draws an eye like those from last week, but for any given colour.
    Write another function eye_picker() that asks the user for the coordinates
    of the centre of an eye, its radius and colour. If the user inputs a valid
    eye colour (blue, grey, green, or brown), then an appropriately coloured eye
    should be displayed in a graphics window. Otherwise, just a 'not a valid eye
    colour' message should be output. Remember to avoid repetitive code.
    """
    centre_coord = eval(
        input(
            "Enter the coordinate for the centre of the eye (as a tuple) > "))
    x_coord, y_coord = centre_coord
    centre = Point(x_coord, y_coord)
    radius = float(input("Enter the radius of the eye > "))
    colours = ["grey", "green", "blue", "green"]
    print(*colours, sep=", ")

    while True:
        try:
            colour = input("Enter the colour of the eye > ").lower()
            if colour in colours:
                break
        except TclError:
            print("Not a valid eye colour")

    win = GraphWin("Coloured eye")
    draw_coloured_eye(win, centre, radius, colour)

    win.getMouse()
    win.close()
Esempio n. 4
0
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():

    # create application window
    win = GraphWin("Three Door Monte", 600, 400)
    win.setCoords(0, 0, 15, 10)
    win.setBackground("darkgrey")

    # create game
    doorMonte = Game(win)

    # create replay and quit button
    quitbutton = Button(win, Point(11.25, 1), 3, 1.5, "Quit")
    quitbutton.activate()
    replay = Button(win, Point(3.75, 1), 3, 1.5, "Replay")

    # event loop
    click = win.getMouse()
    while not quitbutton.clicked(click):
        if doorMonte.doorPicked(click):
            replay.activate()
        elif replay.clicked(click):
            doorMonte.reset()
        click = win.getMouse()

    win.close()
def draw_tour(path_d, all_nodes):
	from graphics import Point, Circle, Line, GraphWin
	maxX = max([x for x, y in all_nodes])
	minX = min([x for x, y in all_nodes])
	maxY = max([y for x, y in all_nodes])
	minY = min([y for x, y in all_nodes])

	N = 750
	norm_x = N/(maxX - minX)
	norm_y = N/(maxY - minY)

	win = GraphWin("TSP", N, N)
	for n in all_nodes:
		c = Point(*norm(n, norm_x, norm_y, minX, minY))
		c = Circle(c, 3)
		c.draw(win)

	for (k, subdict) in path_d.iteritems():
		#t = Text(Point(*subdict['center']*N), k)
		#t.draw(win)
		if not subdict['hasBeenSplit']:
			p = Point(*norm(subdict['center'], norm_x, norm_y, minX, minY))

			c1i, c2i = subdict['connections']
			c1 = Point(*norm(path_d[str(c1i)]['center'], norm_x, norm_y, minX, minY))
			c2 = Point(*norm(path_d[str(c2i)]['center'], norm_x, norm_y, minX, minY))
			l1 = Line(p, c1)
			l2 = Line(p, c2)
			l1.draw(win)
			l2.draw(win)

	win.getMouse()
	win.close()
Esempio n. 7
0
def draw_patch_window():
    """
    9. Write a function draw_patch_window() (without parameters) which displays, in
    a graphics window of size 100 × 100 pixels, the patch design which is
    labelled with the final digit of your student number. The patch design
    should be displayed in red, as in the table. It's important that your
    program draws the patch design accurately, but don't worry if one pixel is
    chopped off at the edge of the window. Note that you don't need to draw a
    border around the patch design.
    """
    win = GraphWin("Patch design", 100, 100)
    for distance in (20, 40, 60, 80, 100):
        line = Line(Point(0, distance), Point(distance, 0))
        line.setFill("red")
        line.setWidth(2)
        line.draw(win)

        line = Line(Point(100 - distance, 0), Point(100, distance))
        line.setFill("red")
        line.setWidth(2)
        line.draw(win)

    for distance in (20, 40, 60, 80):
        line = Line(Point(distance, 100), Point(100, distance))
        line.setFill("red")
        line.setWidth(2)
        line.draw(win)

        line = Line(Point(0, distance), Point(100 - distance, 100))
        line.setFill("red")
        line.setWidth(2)
        line.draw(win)

    win.getMouse()
    win.close()
Esempio n. 8
0
def draw_tour(tour):
    from graphics import Point, Circle, Line, GraphWin
    maxX = max([x for x, y in tour])
    minX = min([x for x, y in tour])
    maxY = max([y for x, y in tour])
    minY = min([y for x, y in tour])

    N = 750
    norm_x = N / (maxX - minX)
    norm_y = N / (maxY - minY)

    win = GraphWin("TSP", N, N)
    for n in tour:
        c = Point(*norm(n, norm_x, norm_y, minX, minY))
        c = Circle(c, 2)
        c.draw(win)

    for i, _ in enumerate(tour[:-1]):
        p1 = norm(tour[i], norm_x, norm_y, minX, minY)
        p2 = norm(tour[i + 1], norm_x, norm_y, minX, minY)
        l = Line(Point(*p1), Point(*p2))
        l.draw(win)

    win.getMouse()
    win.close()
Esempio n. 9
0
def main():
    #create app window
    win = GraphWin("Dice Roller")
    win.setCoords(0, 0, 10, 10)
    win.setBackground('green2')

    #draw 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 shope
    win.close()
Esempio n. 10
0
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()
Esempio n. 11
0
def main():
    fileInput = "C:\Programming\CS138\Week 8\canoe.gif"
    fileOutput = "C:\Programming\CS138\Week 8\grayCanoe.gif"

    image = Image(Point(400, 300), fileInput)  # Getting our image.
    width = image.getWidth()
    height = image.getHeight()
    win = GraphWin("Monochromatic Conversion", width,
                   height)  # Creating our window.
    image.draw(win)

    row = 0  # The starting pixel for our x-axis
    column = 0  # The starting pixel for our y-axis

    win.getMouse()

    for row in range(image.getWidth()):
        for column in range(image.getHeight()):
            r, g, b = image.getPixel(row, column)
            brightness = int(round(0.299 * r + 0.587 * g + 0.114 * b))
            image.setPixel(row, column,
                           color_rgb(brightness, brightness, brightness))
            win.update()

    image.save(fileOutput)
    win.getMouse()
    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():
    #draw main window
    win = GraphWin('Dice Roller', 500, 500)
    win.setCoords(0, 0, 10, 10)
    win.setBackground('green2')

    #draw die and buttons
    die1 = DieView(win, Point(3, 6.5), 2)
    die2 = DieView(win, Point(7, 6.5), 2)
    rollButton = Button(win, Point(3, 2.5), 4, 1, 'Roll Dice')
    rollButton.activate()
    quitButton = Button(win, Point(8, 2.5), 2, 1, 'Quit')

    #event loop
    pt = win.getMouse()
    while not quitButton.clicked(pt):
        if rollButton.clicked(pt):
            a, b = randrange(1, 7), randrange(1, 7)
            die1.setValue(a)
            die2.setValue(b)
            quitButton.activate()
            pt = win.getMouse()

    #clean up
    win.close()
Esempio n. 14
0
def get_window(x=600, y=600):
    try:
        win = GraphWin('', x, y)
        yield ([], [], x, y, win)
        win.getMouse()
    finally:
        win.close()
Esempio n. 15
0
def main():
    win = GraphWin('Dice Roller')
    win.setCoords(0, 0, 10, 10)
    win.setBackground('green2')

    die1 = MultiSidedDie(6)
    die2 = MultiSidedDie(6)
    dieView1 = DieView(win, Point(3, 7), 2)
    dieView2 = 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')

    point = win.getMouse()
    while not quitButton.clicked(point):
        if rollButton.clicked(point):
            die1.roll()
            dieView1.drawValue(die1.getValue())
            die2.roll()
            dieView2.drawValue(die2.getValue())
            quitButton.activate()
        point = win.getMouse()

    win.close()
Esempio n. 16
0
def drawTree(pathFile):
    """Draw the tree of the annotatedFile provided
    
    Args:
        the path of the annotated data file (string)
    Returns:
        a board with the words printed on it (board, from graphics)
        
    """

    listWords = createListWords(pathFile)
    #definition of the Board to print the tree
    boardLength = width
    boardHeight = height
    board = GraphWin("Billy's Tree Board", boardLength, boardHeight)
    #def of my anchor for the first point
    offset = (getRootIndex(listWords) / len(listWords))
    rootPositionX = offset * boardLength + 75
    rootPositionY = offset * boardHeight + 75
    #place the words on the board
    listWordOnBoard = setupRoot(board, rootPositionX, rootPositionY, listWords)
    setupRestOfWords(board, rootPositionX, rootPositionY, listWordOnBoard,
                     listWords)
    #pause, wait for a click on the window, then close properly
    board.getMouse()
    board.close()
Esempio n. 17
0
def main():
    length = 300
    degree = 15
    win = GraphWin("C_Curve Snowflake", 800, 800)
    dir = pi / 2
    turtle = Turtle(Point(475, 225), dir, win)
    C_Curve(turtle, length, degree)
    win.getMouse()
Esempio n. 18
0
def main():
    length = 500
    degree = 5
    win = GraphWin("Koch Snowflake", 800, 800)
    dir = 0
    turtle = Turtle(Point(150, 250), dir, win)
    for i in range(3):
        Koch(turtle, length, degree)
        turtle.turn(120)
    win.getMouse()
Esempio n. 19
0
def view_pop(pop, hold=False):
    win = GraphWin("Polygons", 200, 200)
    for i, indie in enumerate(pop):
        text = Text(Point(180, 180), fitness(indie))
        indie.draw(win)
        text.draw(win)
        time.sleep(0.5)
        indie.undraw()
        text.undraw()
    if hold:
        win.getMouse()
    win.close()
Esempio n. 20
0
def main():
    win = GraphWin("Three Button Monte", 500, 300)
    win.setCoords(-12, -12, 12, 12)
    win.setBackground("green3")

    door1 = Button(win, Point(-7.5, -8), 5, 18, "Door 1")
    door2 = Button(win, Point(0, -8), 5, 18, "Door 2")
    door3 = Button(win, Point(7.5, -8), 5, 18, "Door 3")
    direction = Text(Point(0, 10), "Pick a Door")
    direction.draw(win)
    x = random() * 3
    pt1 = pt2 = pt3 = False
    if 0 <= x < 1:
        pt1 = True
    elif 1 <= x < 2:
        pt2 = True
    else:
        pt3 = True

    door1.activate()
    door2.activate()
    door3.activate()
    click = win.getMouse()

    while door1.clicked(click) or door2.clicked(click) or door3.clicked(click):
        if door1.clicked(click):
            if pt1 == True:
                door1.update(win, "Victory!")
            else:
                if door2.clicked(click):
                    door2.update(win, "Correct Door.")
                    click = win.getMouse()
                else:
                    door3.update(win, "Correct door.")
                    click = win.getMouse()
        elif door2.clicked(click):
            if pt2 == True:
                door2.update(win, "Victory!")
            else:
                if door3.clicked(click):
                    door3.update(win, "Correct Door.")
                    click = win.getMouse()
                else:
                    door1.update(win, "Correct door.")
                    click = win.getMouse()
        else:
            if pt3 == True:
                door3.update(win, "Victory!")
            else:
                if door2.clicked(click):
                    door2.update(win, "Correct Door.")
                    click = win.getMouse()
                else:
                    door1.update(win, "Correct door.")
                    click = win.getMouse()

    win.getMouse()
Esempio n. 21
0
def test():
    window = GraphWin()
    window.setCoords(0, 0, 10, 10)
    r = Rectangle(Point(1, 1), Point(2, 2))
    r.setFill("red")
    r.draw(window)
    for i in range(10):
        time.sleep(1)
        r.undraw()
        r.move(1, 0)
        r.draw(window)
    window.getMouse()
    window.close()
Esempio n. 22
0
def draw_houses(houses, size, door_colour, prob):
    win = GraphWin("Street", 50 * houses * size, 50 * size)
    win.setCoords(0, 0, houses * size, 1)

    for house in range(houses):
        lights_on = random()
        if lights_on > prob:
            lights_on = False
        else:
            lights_on = True
        draw_house(win, door_colour, lights_on, house, size)

    win.getMouse()
def main():
    # create GraphWin
    win = GraphWin("Three Button Monte", 800, 600)
    coordWidth = 10; coordHeight = 10
    factorWidth = win.width / coordWidth; factorHeight = win.height / coordHeight
    win.setCoords(0, 0, coordWidth, coordHeight)

    # place three buttons in window
    # doors = [Button(win, Point(2, 5), 2, 4, door1(), factorWidth, factorHeight),
    #          Button(win, Point(5, 5), 2, 4, door2(), factorWidth, factorHeight),
    #          Button(win, Point(8, 5), 2, 4, door3(), factorWidth, factorHeight)]
    doors = [Button(win, Point(2, 5), 2, 4, "Door 1"),
             Button(win, Point(5, 5), 2, 4, "Door 2"),
             Button(win, Point(8, 5), 2, 4, "Door 3")]
    for door in doors:
        door.setSize(36)
        door.activate()

    # place Quit button in window
    # quitButton = Button(win, Point(8.5, 1.5), 1, 1, "Quit", factorWidth, factorHeight)
    quitButton = Button(win, Point(8.5, 1.5), 1, 1, "Quit")
    quitButton.setSize(24)
    quitButton.activate()

    # place blank message text in window
    result = Text(Point(3.5, 1.5), '')
    result.setSize(18)
    result.draw(win)

    # get mouse click
    pt = win.getMouse()

    # event loop...until Quit clicked
    while not quitButton.clicked(pt):
        # randomly determine which door is correct
        secretDoor = randrange(0, 3)

        # take action for button clicked (1, 2, 3, or Quit)
        if doors[secretDoor].clicked(pt):
            result.setText('Congratulations, you are correct!')
        else:
            result.setText('Sorry, the correct door was door #{}'.format(secretDoor + 1))

        sleep(2)
        result.setText('')

        # get mouse click
        pt = win.getMouse()

    win.close()
Esempio n. 24
0
def table_tennis_scorer():
    """
    8. Write a table_tennis_scorer() function that allows the user to keep track
    of the points of two players in a game of table tennis. In table tennis, the
    first player to reach 11 points wins the game; however, a game must be won
    by at least a two point margin. The points for the players should be
    displayed on two halves of a graphics window, and the user clicks anywhere
    on the appropriate side to increment a player's score. As soon as one player
    has won, a 'wins' message should appear on that side.
    """
    win = GraphWin("Table tennis scorer", 500, 500)
    win.setCoords(0, 0, 1, 1)

    left_score = 0
    right_score = 0

    divider = Line(Point(0.5, 0), Point(0.5, 1))
    divider.draw(win)

    left_score_text = Text(Point(0.25, 0.6), 0)
    left_score_text.setSize(35)
    left_score_text.draw(win)

    right_score_text = Text(Point(0.75, 0.6), 0)
    right_score_text.setSize(35)
    right_score_text.draw(win)

    while not ((left_score >= 11 or right_score >= 11) and
               (left_score >= (right_score + 2) or right_score >=
                (left_score + 2))):
        cursor = win.getMouse()
        if cursor.getX() <= 0.5:
            left_score += 1
            left_score_text.setText(left_score)
        else:
            right_score += 1
            right_score_text.setText(right_score)

    if left_score > right_score:
        winner_text_centre = Point(0.25, 0.5)
    else:
        winner_text_centre = Point(0.75, 0.5)

    winner_text = Text(winner_text_centre, "Winner")
    winner_text.setSize(20)
    winner_text.draw(win)

    cursor = win.getMouse()
    win.close()
Esempio n. 25
0
def five_click_stick_figure():
    """
    9. [harder] Write a five_click_stick_figure() function that allows the user
    to draw a (symmetric) stick figure in a graphics window using five clicks of
    the mouse to determine the positions of its features. Each feature should be
    drawn as the user clicks the points.

    Hint: the radius of the head is the distance between points 1 and 2 — see
    the previous practical.

    Note: only the y-coordinate of point (3) should be used — its x coordinate
    should be copied from point (1).
    """
    win = GraphWin("Five Click Stick Figure", 800, 600)
    message = Text(Point(400, 15), "Click to create your stick figure")
    message.draw(win)

    head_centre = win.getMouse()
    head_centreX, head_centreY = head_centre.getX(), head_centre.getY()
    head_perim = win.getMouse()
    head_perimX, head_perimY = head_perim.getX(), head_perim.getY()
    head_radius = math.sqrt((head_perimX - head_centreX)**2 +
                            (head_perimY - head_centreY)**2)
    head = Circle(head_centre, head_radius)
    head.draw(win)

    torso = win.getMouse()
    torso_line = Line(Point(head_centreX, head_centreY + head_radius),
                      Point(head_centreX, torso.getY()))
    torso_line.draw(win)

    arm_reach = win.getMouse()
    arm_length = head_centreX - arm_reach.getX()
    arms_line = Line(Point(arm_reach.getX(), arm_reach.getY()),
                     Point(head_centreX + arm_length, arm_reach.getY()))
    arms_line.draw(win)

    leg_reach = win.getMouse()
    left_leg_line = Line(Point(head_centreX, torso.getY()),
                         Point(leg_reach.getX(), leg_reach.getY()))
    left_leg_line.draw(win)

    leg_distance = head_centreX - leg_reach.getX()
    right_leg_line = Line(Point(head_centreX, torso.getY()),
                          Point(head_centreX + leg_distance, leg_reach.getY()))
    right_leg_line.draw(win)

    await_user_input(win)
Esempio n. 26
0
def main():
	# create the application window
	win = GraphWin("Dice Poker", 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 - 50, WINDOW_HEIGHT - 50), 75, 50, 'Quit')
	quit.activate()

	roll = Button(win, Point(WINDOW_WIDTH - 125, WINDOW_HEIGHT - 50), 75, 50, 'Roll')
	roll.activate()

	m = (WINDOW_WIDTH / 5) + (5*25)
	for k in range(5):
		hand.append(DieView(win, Point(WINDOW_WIDTH / 2 - m, WINDOW_HEIGHT / 2), 100))
		m -= 125

	scoreText = Text(Point(50, 50), "Score Text Goes Here...")
	scoreText.setTextColor("white")
	scoreText.draw(win)

	global helpText
	helpText = Text(Point(WINDOW_WIDTH - 200, 75), "Help Text Goes Here...")
	helpText.setTextColor("white")
	helpText.draw(win)

	playHand()

	# event loop
	run = True
	while run:
		updateScore(scoreText)
		clickPoint = win.getMouse()
		if (roll.clicked(clickPoint)):
			playHand()
		run = ( (not quit.clicked(clickPoint)) and (playerAmount >= 10) )
	updateScore(scoreText)

	# By now, player has exhausted funds
	if (playerAmount <= 10):
		helpText.setText(helpText.getText() + "\nYou've don't have enough for another roll.")
		roll.deactivate()
		while (not quit.clicked(clickPoint)): # Wait till the user clicks quit
			clickPoint = win.getMouse()

	# close the window
	win.close()
Esempio n. 27
0
def main():
    win = GraphWin("Dice Poker", 600, 400)
    win.setBackground("green3")
    banner = Text(Point(300, 30), "Python Poker Parlor")
    banner.setSize(24)
    banner.setFill("yellow2")
    banner.setStyle("bold")
    banner.draw(win)
    letsPlayBtn = Button(win, Point(300, 300), 400, 40, "Let's Play!")
    letsPlayBtn.activate()
    exitBtn = Button(win, Point(300, 350), 400, 40, "Exit")
    exitBtn.activate()
    showHighScores(win)

    while True:
        p = win.getMouse()

        if letsPlayBtn.clicked(p):
            win.close()
            inter = GraphicsInterface()
            app = PokerApp(inter)
            app.run()
            break

        if exitBtn.clicked(p):
            win.close()
            break
Esempio n. 28
0
def get_image_path():
    width, height = 300, 150
    win = GraphWin("Image Path", width, height)
    win.setBackground(color_rgb(0, 0, 0))

    path_entry = Entry(Point(width // 2, height // 2 - 50), 30)
    path_entry.draw(win)

    ok_button = Rectangle(Point(width - 50, height - 50),
                          Point(width - 5, height - 5))
    ok_button.setFill(color_rgb(255, 255, 255))
    ok_button.draw(win)
    ok_button_text = Text(ok_button.getCenter(), "OK")
    ok_button_text.setSize(15)
    ok_button_text.draw(win)

    while True:
        click = win.getMouse()
        clickx = click.getX()
        clicky = click.getY()

        if ok_button.getP1().getX() <= clickx <= ok_button.getP2().getX(
        ) and ok_button.getP1().getY() <= clicky <= ok_button.getP2().getY():
            win.close()
            return str(path_entry.getText())
Esempio n. 29
0
def main():
    win = GraphWin ( "Click and Type", 400, 400)
    for i in range(10):
        pt = win.getMouse()
        key = win.getKey()
        label = Text (pt, key)
        label.draw(win)
Esempio n. 30
0
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()
Esempio n. 31
0
def peas_in_a_pod():
    """
    5. Write a function peas_in_a_pod() that asks the user for a number, and
    then draws that number of 'peas' (green circles of radius 50) in a 'pod'
    (graphics window of exactly the right size). E.g. if the user enters 5, a
    graphics window of size 500 × 100 should appear.
    """
    peas = int(input("Enter a number of peas: "))
    win = GraphWin("Peas in a pod", peas * 100, 100)
    for pea in range(peas):
        circle = Circle(Point(50 + pea * 100, 50), 50)
        circle.setFill("green")
        circle.draw(win)

    win.getMouse()
    win.close()
Esempio n. 32
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--size", type=int, default=3, help="Size of k")
    args = parser.parse_args()

    win = GraphWin("My Circle", WIN_SIZE, WIN_SIZE)

    k = args.size
    m = k * (k - 1) + 1
    r = min(pi * R / m * 0.50, 20)

    ds = DiffState(k)
    ds.search()

    points = []
    for i in range(m):
        ang = 2 * pi * i / m
        center = (CENTER[0] + R * sin(ang), CENTER[1] - R * cos(ang))
        points.append(Point(center[0], center[1]))

    if m < 20:
        for i in range(m):
            for j in range(i, m):
                if not (i in ds.current and j in ds.current):
                    l = Line(points[i], points[j])
                    l.draw(win)
                    l.setOutline(all_color)

    for i in range(m):
        for j in range(i, m):
            if i in ds.current and j in ds.current:
                l = Line(points[i], points[j])
                l.setWidth(3)
                l.draw(win)
                l.setOutline(set_color)

    for i in range(m):
        c = Circle(points[i], r)
        c.setFill("red")
        c.draw(win)

    win.getMouse()
    win.close()
Esempio n. 33
0
    def pulsado(self, p):
        if p.getX() in range(self.xmin, self.xmax) and p.getY() in range(self.ymin, self.ymax):
            return True
        else:
            return False
    def activar(self):
        self.etiqueta.setTextColor('#000')
        self.estado = True
        
    def desactivar(self):
        self.etiqueta.setTextColor('#666')
        self.estado = False
        
        
        
    
w = GraphWin('Mi boton', 600, 400)
b1 = Boton(w, Point(300, 200), 80, 40, 'Okey')
b2 = Boton(w, Point(300, 250), 80, 40, 'Activar')

while True:
    p = w.getMouse()
    if b1.pulsado(p):
        b1.color('blue')
    if b2.pulsado(p):
        if b2.estado:
            b2.desactivar()
        else:
            b2.activar()
        
w.getMouse()