I have been attempting to write a program that takes an input from a button class and a graphics class that creates a gui for a game called three button monte. So far I've been able to get it to sort of work. The point is to have the "game" randomly choose a button that "wins". The player is supposed to click which button they think the winner is and the button is supposed to either activate and say win. So far I've been only able to make the window open. My biggest issue is attempting to get the program to come up with the random button. I would appreciate any help or input for getting this to run. Here's the code I have I know it's still pretty screwed up but my biggest issue has been the coding for the random points. Thanks for any help that you can give me.

from graphics import *
from button import Button
from random import *

def main():
    win = GraphWin("Three Button Monte")
    win.setCoords(0, 0, 100, 100)

    #draw buttons
    button1 = Button(win, Point(20, 50), 27, 40, "Door 1")
    button2 = Button(win, Point(50,50), 27, 40, "Door 2")
    button3 = Button(win, Point(80,50), 27, 40, "Door 3")
    button4 = Button(win, Point(20, 50), 27, 40, "Yes!")
    button5 = Button(win, Point(50,50), 27, 40, "Yes!")
    button6 = Button(win, Point(80,50), 27, 40, "Yes!")
    quitButton = Button(win, Point(50,10), 20, 10, "Quit")
    x = 0
    y = 0

    #Event Loop
    pt = win.getMouse()
    while not quitButton.clicked(pt):
        ranx,rany = randrange(Point(x, y))
        if (ranx, rany) >= button1(Point(x,y)):
            if button1.clicked():
                print ("No")
        if (ranx, rany) >= button2(Point(x,y)):
            if button2.clicked():
                print ("No")
        if (ranx, rany) >= button3(Point(x,y)):
            if button3.clicked():
                print ("No!")
    pt= win.getMouse()


(ranx, rany) >= button1(Point(x,y)) is most likely not the same data type and therefore not comparable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.