onscreenclick
不用等待你的点击。它只通知
mainloop
单击时必须执行的功能。
主回路
做所有事情-它创建主窗口,从操作系统获取鼠标/键盘事件,将事件发送到窗口中的元素/小部件,运行分配给
屏幕点击
/
ontimer
/等等,在屏幕上重画元素等等。
所以
print(position)
在偶数之前执行
主回路
打开窗口。
你必须在里面打印
get()
import turtle as t
# --- functions ---
def get(x, y):
print("(", x, ",", y, ")")
if y > 0:
if x < 0:
position = 1
else:
position = 2
else:
if x < 0:
position = 3
else:
position = 4
print('pos:', position)
# --- main ---
# inform mainloop what function use when you click
t.onscreenclick(get)
# start "the engine" (event loop)
t.mainloop()