我尝试使用Tkinter进行简单的python游戏。 当我点击目标点时,我想要处理这个坐标。 我有这段代码:
if __name__ == "__main__":
root = Tk()
#setting canvas
frame = Frame(root, bd=0, relief=SUNKEN)
frame.grid_rowconfigure(0, weight=1)
frame.grid_columnconfigure(0, weight=1)
canvas = Canvas(frame, bd=0, width=600, height=600,xscrollcommand=xscroll.set, yscrollcommand=yscroll.set)
canvas.grid(row=0, column=0, sticky=N+S+E+W)
frame.pack(fill=BOTH, expand=1)
def get_coords(event, TPointsDict,k):
k+=1
canvas.create_circle(event.x, event.y, 7, fill="blue", outline="#DDD", width=2)
return event.x, event.y
TPointsDict={"target1":(130,220), "target_2":(240, 190)}
k=0
canvas.bind("<Button 1>", lambda event, arg=TPointsDict, arg2=k: get_coords(event, arg, arg2))
root.mainloop()
我想从函数 get_coords 返回coords,然后用它们做一些操作。 我怎样才能捕获 get_coords 函数的返回值?
谢谢!