Tkinter入门
前页 | 第4章. Tkinter类 | 后页

# 混入

几个混入类型和其它辅助类(一个混入(`Mixin`)类型是一个被设计为与其它使用多继承类相结合的类).当你使用Tkinter时,你应该不去直接访问混入类.

## 执行混入

`Misc` 类class is used as a mixin by the root window and widget classes. It provides a large number of Tk and window related services, which are thus available for all Tkinter core widgets. This is done by delegation ; the widget simply forwards the request to the appropriate internal object.

The `Wm` class is used as a mixin by the root window and `Toplevel` widget classes. It provides window manager services, also by delegation.

Using delegation like this simplifies your application code: once you have a widget, you can access all parts of Tkinter using methods on the widget instance.

## 几何混入

`Grid` , `Pack` , 和 `Place` 类 are used as mixins by the widget classes. They provide access to the various geometry managers, also via delegation.

表 4-2. 几何混入

Manager | Description
--- | ---
`Grid` | 栅格几何管理器允许你创建一个类似表的布局形式, 组件都被组织在一个2维栅格里.通过调用`grid` 方法使用栅格管理器.
`Pack` | pack 几何管理器让你创建一个packgeometry manager lets you create a layout by "packing" the widgets into a parent widget, by treating them as rectangular blocks placed in a frame. To use this geometry manager for a widget, use the `pack` method on that widget to set things up.
`Place` | The place geometry manager lets you explicitly place a widget in a given position. To use this geometry manager, use the `place` method.

## 组件配置管理

The `Widget` class mixes the `Misc` class with the geometry mixins, and adds configuration management through the `cget` and `configure` methods, as well as through a partial dictionary interface. The latter can be used to set and query individual options, and is explained in further detail in the next chapter.

前页 | 首页 | 后页
Tkinter 类 | 向上 | 组件配置