Tk Tutorial - 10. Organizing Complex Interfaces

来源:互联网 发布:api数据调用 编辑:程序博客网 时间:2024/05/21 06:24

White space

You've seen how grid can help by making it easy to align widgets with each other. White space is another useful aid.

Separator

A second approach to grouping widgets in one display is to place a thin horizontal or vertical rule between groups of widgets; often this can be more space efficient than using white space, which may be relevant for a tight display. Tk provides a very simpleseparator widget for this purpose.

Separators are created using the ttk.Separator function:

s = ttk.Separator(parent, orient=HORIZONTAL)

Label Frames

A labelframe widget, also commonly known as a group box, provides another way to group related components. It acts like a normalttk::frame, in that you will normally use it as a container for other widgets yougrid inside it.

Labelframes are created using the ttk.Labelframe function:

lf = ttk.Labelframe(parent, text='Label')

Paned Windows

A panedwindow widget lets you stack two or more resizable widgets above and below each other (or to the left and right). The user can adjust the relative heights (or widths) of each pane by dragging asash located between them.

Panedwindows are created using the ttk.Panedwindow function:

p = ttk.Panedwindow(parent, orient=VERTICAL)# first pane, which would get widgets gridded into it:f1 = ttk.Labelframe(p, text='Pane1', width=100, height=100)f2 = ttk.Labelframe(p, text='Pane2', width=100, height=100); # second panep.add(f1)p.add(f2)
A paned window is either "vertical" (it's panes are stacked vertically on top of each other),or"horizontal". Importantly, all of the panes that you add to the paned window must be a direct child of the paned window itself.

Calling the "add" method will add a new pane at the end of the list of panes. The"insertposition subwindow" method allows you to place the pane at the given position in the list of panes (0..n-1); if the pane is already managed by the paned window, it will be moved to the new position. You can use the"forget subwindow" to remove a pane from the paned window; you can also pass a position instead of a subwindow.

Notebook

A notebook widget uses the metaphor of a tabbed notebook to let the user switch between one of severalpages, using an index tab. In this case, unlike with paned windows, we're only allowing the user to look at a single page (akin to a pane) at a time.

Notebooks are created using the ttk.Notebook function:

n = ttk.Notebook(parent)f1 = ttk.Frame(n); # first page, which would get widgets gridded into itf2 = ttk.Frame(n); # second pagen.add(f1, text='One')n.add(f2, text='Two')
The operations on tabbed notebooks are similar to those on paned windows. Each page is typically a frame, again a direct child (subwindow) of the notebook itself. A new page and its associated tab are added to the end of the list of tabs with the "add subwindow ?option value...?" method.The "text" tab option is used to set the label on the tab; also useful is the"state"tab option, which can have the value "normal", "disabled" (not selectable), or"hidden".

To insert a tab at somewhere other than the end of the list, you can use the "insert position subwindow ?option value...?", and to remove a given tab, use the"forget" method,passing it either the position (0..n-1) or the tab's subwindow. You can retrieve the list of all subwindows contained in the notebook via the"tabs" method.

To retrieve the subwindow that is currently selected, call the "select" method, and change the selected tab by passing it either the tab's position or the subwindow itself as a parameter.

To change a tab option (like the text label on the tab or its state), you can use the"tab(tabid, option=value"method (where "tabid" is again the tab's position or subwindow); omit the"=value" to return the current value of the option.

from: http://www.tkdocs.com/tutorial/complex.html

0 0
原创粉丝点击