What is a good way to dynamically display different content (in Tcl / Tk)?

I have a set of radiobuttons (say with options 1 and 2) and you need to show some widget based on 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 any case, the received content will be displayed in the same area in the window.

How can I switch between multiple widgets?

This answer made me think that I should use panedwindow and frames , but I do not quite understand how to switch between different content.

+4
source share
2 answers

When using panedwindow, you can switch between areas of the content by deleting the frame and adding a new one to replace it. See this manual page for a description of the forget and add / insert commands for ttk :: panedwindow.

Code example:

 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 

You can adapt this code to your needs. Just create all the views that you may need, and then change them to the desired parameters.

+3
source

A very simple way is to use one frame for each data set. Use grid to put all of them in one row and column. Then all you have to do is raise the frame and the children to the top of the stacking order.

Another technique starts the same way, but instead of using a raise, do a grid remove depending on which frame is currently displayed, and then grid on the one that will be shown. With grid remove , grid remembers all the settings, so you will not need to specify all the parameters again the next time you want it to appear.

+1
source

All Articles