在 tcl tk gui 中隐藏和显示框架

发布于 2024-12-10 08:51:51 字数 613 浏览 0 评论 0原文

我想制作一个可以隐藏和显示交替的框架。问题是 Tk 不提供任何隐藏/解包命令。我使用 vtcl,有一个选项“Window hode”,它仅隐藏顶层窗口。现在我想隐藏一个框架,然后再次显示同一框架。它可以被认为是拆开一帧并显示另一帧。我的代码可以是这样的:

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
    }
}

在此过程中,$top.frame1$top.frame2之前已填充,$i的值为因此,当调用此过程时,$top.frame1$top.frame2 会交替显示。我想知道是否存在像 unpack 这样的命令可以帮助我做到这一点?顺便说一下,这里的unpack只是一个想法。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失与倦" 2024-12-17 08:51:51

我认为 packforget 命令可能就是您正在寻找的:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文