【发布时间】:2019-10-18 19:18:38
【问题描述】:
我正在尝试使用turtle python 编写程序,询问用户一个数字并让他在屏幕上单击相同的次数。
import turtle
t = turtle.Turtle()
count = 0
def up_count(x,y):
global count
count = count + 1
print count
return
def start():
num1=int(raw_input("enter number"))
print "in the gaeme you need to enter number and click on button",num1,"times"
s = t.getscreen()
if not num1 == count:
s.onclick(up_count)
else:
t.mainloop()
start()
问题是当 num1 == count 时我无法退出 mainloop。
我怎样才能退出主循环?
【问题讨论】:
-
次要:第二个函数中不需要
global count,因为它不会改变这个全局变量。 -
参考文档mainloop 开始事件循环而不是退出它。您可以查看How to close a python turtle window