I want to make a frame that can be hidden and shown alternatively. The problem is Tk does not provide any hide/unpack command. I use vtcl and there is an option "Window hode" which only hides the window at top level. Now I want to hide a frame and later show the same frame again. It can be thought of as unpacking one frame and showing the other. My code can 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 previously filled and value of $i
is toggled hence $top.frame1
and $top.frame2
are shown alternatively when this proc is called. All, I want to know is that does there exists and command like unpack
which can help me do this? By the way, unpack
here is just an idea.
I think that the pack forget command might 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
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