How to clear Tkinter Canvas?

后端 未结 3 1907
刺人心
刺人心 2020-12-13 17:26

When I draw a shape using:

canvas.create_rectangle(10, 10, 50, 50, color=\"green\")

Does Tkinter keep track of the fact that it was created

3条回答
  •  有刺的猬
    2020-12-13 17:52

    Items drawn to the canvas are persistent. create_rectangle returns an item id that you need to keep track of. If you don't remove old items your program will eventually slow down.

    From Fredrik Lundh's An Introduction to Tkinter:

    Note that items added to the canvas are kept until you remove them. If you want to change the drawing, you can either use methods like coords, itemconfig, and move to modify the items, or use delete to remove them.

提交回复
热议问题