Hide and show frame in tcl tk gui

I want to create a frame that can be hidden and shown as an alternative. The problem is that Tk does not provide the hide / unpack command. I use vtcl, and there is a "Window hode" option that only hides the window at the top level. Now I want to hide the frame, and then show the same frame again. It can be considered as unpacking one frame and displaying another. My code might be like this:

proc show1hide2 { } { global i top if {$i == 1} { unpack $top.frame1 pack $top.frame2 set i 0 } else { unpack $top.frame2 pack $top.frame1 set i 1 } } 

In this procedure, $top.frame1 and $top.frame2 were pre-populated and the value of $i switched, so $top.frame1 and $top.frame2 are shown alternatively when calling this proc. That's it, I want to know that there exists and exists a command like unpack that can help me do this? By the way, unpack is just an idea.

+4
source share
1 answer

I think the pack forget command may be what you are looking for:

 proc toggle {} { global state if {$state == 1} { pack forget .r pack .g -side bottom -fill x set state 0 } else { pack forget .g pack .r -side bottom -fill x set state 1 } } set state 1 # Make the widgets label .r -text "Red Widget" -bg red label .g -text "Green Widget" -bg green button .tog -text "Toggle" -command toggle # Lay them out pack .tog pack .r -side bottom -fill x 
+8
source

All Articles