4

我有一组radiobuttons(比如说,有选择 1 和 2)并且需要根据用户的选择显示一些小部件。例如,如果他们选择 1,我会向他们展示 alabelframe和几个radiobuttons;而如果他们选择 2,我会向他们展示 alabelframe和 some buttons。在任何一种情况下,生成的内容都将显示在窗口的同一区域中。

像这样在多个小部件显示之间切换的好方法是什么?

这个答案让我认为我应该使用panedwindowand frames,但我不太明白如何在不同的内容之间切换。

4

2 回答 2

3

使用panedwindow时,您应该能够通过删除框架并添加新框架来替换它来在内容窗格之间切换。有关ttk::panedwindow的和/命令的说明,请参阅此手册页。forgetaddinsert

示例代码:

package require Ttk

# Create a panedwindow
ttk::frame .f
ttk::panedwindow .f.pane -orient vertical

# Create three panes
ttk::frame .f.pane.one -height 50 -width 50
ttk::label .f.pane.one.l -text "Number one"
pack .f.pane.one.l

ttk::frame .f.pane.two -height 50 -width 50
ttk::label .f.pane.two.l -text "Number two"
pack .f.pane.two.l

ttk::frame .f.pane.three -height 50 -width 50
ttk::label .f.pane.three.l -text "Number three"
pack .f.pane.three.l

# Add frames one and two to the panedwindow
.f.pane add .f.pane.one
.f.pane add .f.pane.two

pack .f.pane -expand 1 -fill both
pack .f -expand 1 -fill both

# Replace pane one with pane three
.f.pane insert 1 .f.pane.three
.f.pane forget 2 

您可以根据自己的需要调整此代码。只需创建您可能需要的所有视图,然后根据需要交换它们。

于 2010-09-03T20:33:38.437 回答
1

A really simple way is to use one frame for each set of data. Use grid to place them all in the same row and column. Then all you need to do is raise the frame and it's children to the top of the stacking order.

Another technique starts out the same but instead of using raise, do grid remove on whichever frame is currently being shown, and then grid on the one to be shown. With grid remove, grid remembers all of the settings so that you don't have to specify all of the options again the next time you want it to appear.

于 2010-09-03T21:07:24.883 回答