动态显示不同内容(在 Tcl/Tk 中)的好方法是什么?
我有一组单选按钮(例如,选择 1 和 2),需要根据用户的选择显示一些小部件。例如,如果他们选择 1,我会向他们展示一个带有多个单选按钮的标签框;然而,如果他们选择 2,我会向他们展示一个带有一些按钮
的labelframe
。无论哪种情况,生成的内容都将显示在窗口的同一区域中。
像这样在多个小部件显示之间切换的好方法是什么?
这个答案让我认为我应该使用 panedwindow
和 frames
,但我不太明白如何在不同内容之间切换。
I have a set of radiobuttons
(say, with choices 1 and 2) and need to show some widget based off of the user's choice. For example, if they chose 1, I would show them a labelframe
with several radiobuttons
; whereas, if they chose 2, I would show them a labelframe
with some buttons
. In either case, the resulting content would be shown in the same area on the window.
What is a good way to switch between multiple widget displays like this?
This answer has me thinking that I should use a panedwindow
and frames
, but I don't quite see how I would switch between different content.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 panedwindow 时,您应该能够通过删除框架并添加新框架来在内容窗格之间切换一个来代替它。有关
的说明,请参阅本手册页忘记 ttk::panedwindow 的
和add
/insert
命令。示例代码:
您可以根据自己的需要调整此代码。只需创建您可能需要的所有视图,然后根据需要将它们换入和换出即可。
When using a panedwindow, you should be able to switch between content panes by deleting a frame and adding a new one to replace it. See this manual page for a description of the
forget
andadd
/insert
commands for ttk::panedwindow.Sample code:
You can adapt this code for your own needs. Simply create all the views that you might need, and then swap them in and out as needed.
一种非常简单的方法是对每组数据使用一个帧。使用
grid
将它们全部放置在同一行和同一列中。然后您需要做的就是将框架及其子项提升到堆叠顺序的顶部。另一种技术的起点相同,但不是使用 raise,而是在当前显示的帧上执行
grid remove
,然后在要显示的帧上执行grid
。通过grid remove
,grid
会记住所有设置,这样您下次希望它显示时就不必再次指定所有选项。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 thengrid
on the one to be shown. Withgrid 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.