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)
    win.setBackground("blue")


    #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!")
    button1.activate()
    button2.activate()
    button3.activate()
    button4.deactivate()
    button5.deactivate()
    button6.deactivate()
    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():
                button4.activate()
            else:
                print ("No")
        if (ranx, rany) >= button2(Point(x,y)):
            if button2.clicked():
                button5.activate()
            else:
                print ("No")
        if (ranx, rany) >= button3(Point(x,y)):
            if button3.clicked():
                button6.activate()
            else:
                print ("No!")
        quitButton.activate()
    pt= win.getMouse()

main()

(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.