Tk Tutorial - 10. Organizing Complex Interfaces

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 simple separator 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 normal ttk::frame, in that you will normally use it as a container for other widgets you grid 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 a sash 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 pane
p.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"insert position 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 several pages, 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 it
f2 = ttk.Frame(n); # second page
n.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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值