使用Zelle Graphics(Monty Hall Stimulation)错误:_tkinter.TclError:屏幕距离不好“蓝色”

时间:2017-10-12 22:16:25

标签: python python-3.x tkinter error-handling zelle-graphics

该程序模拟(使用Zelle Graphics)Monty Hall Stimulation。 我很新,尤其是图形。

Monty Hall的问题来自Monty Hall主持的“Let's Make a Deal”电视游戏节目。在节目结束时,一位幸运的选手有机会像汽车一样赢得大奖。他们被带到3个闭门。在两扇门的后面是一个“zonk” - 一个没有人想要像山羊一样的奖品。剩下的门藏了一辆车。选手选择了一扇门。然后蒙蒂霍尔将打开参赛者没有选择的一扇门,露出了一个zonk。在那时,参赛者可以选择坚持他们选择的门或拿走剩下的门。

当我运行时,然后双击中间门,它会给我一个错误并且不会显示Zonk [一个浣熊 - 没有人想要的奖品] .. 然而,当我跑,然后点击门1或运行然后点击门2,错误没有出现和Zonk被揭示。 这些点击控件在函数processingDoor_Clicks()

中处理

错误是:_tkinter.TclError: bad screen distance "blue"

导致此错误的原因是什么?

from graphics import *
from random import randint

def main():
    print("Monty Hall Game")
    win = GraphWin("Monty Hall Game", 800, 900)
    win.setBackground("purple")
    switch, stay, play, doorOne, doorTwo, doorThree = drawAll(win)
    carSpot, zonkOne, zonkTwo = place_Zonk_Car(win)
    processDoors_clicks(win, carSpot, zonkOne, zonkTwo, doorOne, doorTwo, doorThree)
    #processDoors_clicks(win, carSpot, zonkOne, zonkTwo)


def drawAll(win):
    switch, stay, play = drawButtons(win)
    doorOne, doorTwo, doorThree = drawDoors(win)
    return switch, stay, play, doorOne, doorTwo, doorThree

#keep position of car pass for arg (in a box) // 
#ifs click to see if clicks are in boxes 
#if win.getmouse //getx and gety// for click

def place_Zonk_Car(win):
    carSpot = randint(1,3)

    print(carSpot)

    if carSpot == 1: #left
        drawCar = Image(Point(150, 375), 'prize2.png')
        draw_zonkOne = Image(Point(400, 375), 'box_of_possums.gif') #from draw photo 2
        draw_zonkTwo = Image(Point(650, 375), 'door3.png') #from draw photo 3

        print("behind foor one")
    elif carSpot == 2: #middle
        drawCar = Image(Point(400, 375), 'prize2.png')
        draw_zonkOne = Image(Point(150, 375), 'box_of_possums.gif') #drawn from 1
        draw_zonkTwo = Image(Point(650, 375), 'box_of_possums.gif') #drawn from 3

        print("behind door two")
    elif carSpot == 3: #right
        drawCar = Image(Point(650, 375), 'prize2.png')
        draw_zonkOne = Image(Point(150, 375), 'box_of_possums.gif') #left from 1
        draw_zonkTwo = Image(Point(400, 375), 'box_of_possums.gif')#drawn from 2

        print("behind door three")
    #drawCar.draw(win)
    #draw_zonkOne.draw(win)
    #draw_zonkTwo.draw(win)
    return drawCar, draw_zonkOne, draw_zonkTwo #store to draw later, but reveal one earlier on



def drawButtons(win):
    switchOption = Rectangle(Point(50, 500), Point(250, 550))
    switchOption.draw(win)
    switchOption.setFill('white')
    switchText  = Text(Point(150, 525), "switch")
    switchText.draw(win)

    stayOption = Rectangle(Point(300, 500), Point(500, 550))
    stayOption.draw(win)
    stayOption.setFill('white')
    stayText  = Text(Point(400, 525), "stay")
    stayText.draw(win)

    playOption = Rectangle(Point(550, 500), Point(750, 550))
    playOption.draw(win)
    playOption.setFill('white')
    playText  = Text(Point(650, 525), "play again")
    playText.draw(win)

    return switchOption, stayOption, playOption

def drawDoors(win):
    presentText = Text(Point(400, 200), "Click a Door")
    presentText.draw(win)

    doorOne = Rectangle(Point(50, 300), Point(250, 450))
    doorOne.draw(win)
    doorOne.setFill('white')
    doorPhotoOne = Image(Point(150, 375), 'door1.png')
    doorPhotoOne.draw(win)

    doorTwo = Rectangle(Point(300, 300), Point(500, 450))
    doorTwo.draw(win)
    doorTwo.setFill('white')
    doorPhotoTwo = Image(Point(400, 375), 'door2.png')
    doorPhotoTwo.draw(win)

    doorThree = Rectangle(Point(550, 300), Point(750, 450))
    doorThree.draw(win)
    doorThree.setFill('white')
    doorPhotoThree = Image(Point(650, 375), 'door3.png')
    doorPhotoThree.draw(win)

    return doorOne, doorTwo, doorThree


#def montyHallGame(win):

def processDoors_clicks(win, carSpot, zonkOne, zonkTwo, doorOne, doorTwo, doorThree):
    #find clicks
    click_Y_Val = win.getMouse().getY() #user picks doors (x and y) -- monty will later
    click_X_Val = win.getMouse().getX()
    #must be in this

    if (click_X_Val >= 50 and click_X_Val <= 250) and (click_Y_Val >= 300 and click_Y_Val <= 450): # door 1
        doorOne.setOutline("blue")
        doorOne.setWidth(4)
        zonkOne.draw(win)


    elif (click_X_Val >= 300 and click_X_Val <= 500) and (click_Y_Val >= 300 and click_Y_Val <= 450): # door 2
        doorTwo.setWidth("blue")
        doorOne.setWidth(4)
        zonkTwo.draw(win)


    elif (click_X_Val >= 550 and click_X_Val <= 750) and (click_Y_Val >= 300 and click_Y_Val <= 450): # door 3
        doorThree.setOutline("blue")
        doorOne.setWidth(4)
        zonkOne.draw(win)

0 个答案:

没有答案