如何单击特定按钮?

2024-09-30 06:30:38 发布

您现在位置: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()

Tags: thefromimport游戏地方按钮winpull
1条回答
网友
1楼 · 发布于 2024-09-30 06:30:38

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

相关问题 更多 >

    热门问题