[英]Program not ending after 'if' executes events
it is supposed to end the onclick
after pressing on the circle but it continues anyway. 它应该在按下圆圈后结束
onclick
,但它仍然继续。
from turtle import *
l=0
h=True
circle(5)
def m(x,y):
global l
global h
goto(x,y)
if((x>=0 and x<=10) and (y>=0 and y<=10)):
h=False
goto(0,0)
def r():
onscreenclick(m)
if h:
ontimer(r(),1000)
mainloop()
I can't figure out what your code is supposed to do. 我无法弄清楚你的代码应该做什么。 From the title, clicking on the dot should end the program.
从标题中,单击点应该结束程序。 From the text, clicking on the dot should turn off the
onscreenclick()
event handler but you'd have no visible way to verify that this had happened or not. 从文本中,单击点应关闭
onscreenclick()
事件处理程序,但是您没有可见的方法来验证是否发生了这种情况。
Assuming ending the program was the goal, here's how we might rework your program to do so: 假设结束程序是目标,我们可以通过以下方式重新编写程序:
from turtle import *
def m(x, y):
if -5 <= x <= 5 and -5 <= y <= 5:
bye() # exit from mainloop()
hideturtle()
penup()
dot(10) # use dot (diameter) instead of circle (radius) as it's centered
goto(100, 100) # get the turtle away from center
onscreenclick(m)
mainloop()
However, if this behavior is your goal, we can simplify the code by making the turtle itself the dot and set the onclick()
event on the turtle instead of the screen: 但是,如果这个行为是你的目标,我们可以通过使乌龟本身成为点并在乌龟而不是屏幕上设置
onclick()
事件来简化代码:
from turtle import *
def m(x, y):
bye() # exit from mainloop()
shape('circle')
shapesize(0.5)
onclick(m)
mainloop()
If I've completely missed the point of your question, please edit your question to clarify the behavior and goals of your program. 如果我完全错过了您的问题,请编辑您的问题以澄清您的计划的行为和目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.