6

I know that pack and pack_forget can be used to show or hide widgets. Which are the equivalent commands for items on a canvas?

Notice: It would be better to keep the complete item information, including its position. This is not the case with pack/pack_forget, where you need to inform the position again whenever you use pack.

bmello
  • 1,625
  • 2
  • 15
  • 23

2 Answers2

8

As mentioned in a comment by @CommonSense, you can toggle hide/show canvas items using:

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

from a comment on an answer to this question, you get a similar functionality for widgets positioned with the grid geometry manager:

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

Reblochon Masque
  • 33,202
  • 9
  • 48
  • 71
1

You need to use:

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

as mentioned in @Reblochon Masque answer although attention to the id. this id is the return value of the widget placement method

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

not the widget's name

Kostas Markakis
  • 135
  • 2
  • 10