如何在 tkinter 上隐藏和显示 canvas 项?

How to hide and show canvas items on tkinter?

我知道 packpack_forget 可用于显示或隐藏小部件。 canvas 上的项目有哪些等效命令?

注意:最好保留完整的物品信息,包括物品的位置。 pack/pack_forget不是这样的,每次使用pack的时候都需要重新通知位置

如@CommonSense 的评论所述,您可以 toggle hide/show canvas 项目使用:

canvas.itemconfigure(id, state='hidden'/'normal')

a comment on an answer to this question 开始,您将获得与 grid 几何管理器定位的小部件类似的功能:

grid_remove is another option. It's advantage over grid_forget is that grid will remember all of the options, so that a simple grid() will put it right back. There is no pack_remove

您需要使用:

canvas.itemconfigure(id, state='hidden'/'normal')

正如@Reblochon Masque 回答中提到的,尽管注意了 id。此 id 是小部件放置方法的 return 值

id = parent.create_window(x, y, window=my_widget_name)

不是小部件的名称