Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hide and show frame in tcl tk gui

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.

like image 943
user954134 Avatar asked Oct 18 '11 06:10

user954134


1 Answers

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
like image 173
Jackson Avatar answered Sep 22 '22 02:09

Jackson