如何点击特定按钮?

时间:2017-10-28 20:25:11

标签: python

我是python的新手。 当点击按钮"pull"时,我正试图让游戏开始。 但是我所拥有的,只要我点击win,就会开始游戏。

from graphics import*
from random import*
from time import*
def main():
    # Creating the window
    win = GraphWin("Clay Target Control Panel",400,400)

    # "Pull" rectangle and color
    pullrec = Rectangle(Point(150,290),Point(250,330))
    pullrec.setFill("light salmon")
    pullrec.draw(win)
    pullmess = Text(Point(200,310),"PULL")
    pullmess.setSize(11)
    pullmess.setStyle("bold")
    pullmess.draw(win)

    # Start the game when "Pull" rectangle is clicked.
    while True:
        mouse = win.getMouse()
        if pullrec:
            win.getMouse()

1 个答案:

答案 0 :(得分:0)

我怀疑win.getMouse会阻塞,等待鼠标点击。 pullrec绑定到一个矩形。 bool(<rectangle>)True,因此if rectangle始终会触发。您需要调用一些方法来查看单击鼠标的位置。我知道如何使用tkinter,而不是graphics