我遇到了一些问题。我需要正方形才能从画布边框反弹/我需要得到正方形的 x 和 y。我该怎么做?
我知道我必须使用winfo_x
and winfo_y
,我不知道如何使用它。
from tkinter import*
root = Tk()
cnv = Canvas(root, bg='yellow', width=700, height=500)
cnv.pack()
rect = cnv.create_rectangle(50, 50, 100, 100, fill='black')
def paintloop():
cnv.move(rect, 2, 2)
root.after(10, paintloop)
root.after(0, paintloop)
root.mainloop()