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.
A transparent ColorKey can be set with SetLayeredWindowAttributes while we just use LWA_COLORKEY the alpha parameter has no use to us. Important note: After defining a transparent colorkey, everything in that canvas with that color will be transparent.
To display data we have to use insert() function. insert function takes two parameters. In our program, we have used entry widgets to capture the information provided by the user, and then we have to frame a sentence & that sentence is displayed in another Entry widget.
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 overgrid_forget
is thatgrid
will remember all of the options, so that a simplegrid()
will put it right back. There is no pack_remove
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With