python手记(22)

来源:互联网 发布:角度尺软件 编辑:程序博客网 时间:2024/05/27 20:52
Traits UI快速设计
#  Copyright (c) 2007, Enthought, Inc.#  License: BSD Style.# wizard.pyfrom traits.api import HasTraits, Int, Strclass Employee(HasTraits):    name = Str    department = Str    salary = Int    bonus = IntEmployee().configure_traits()

Traits UI 下载地址:

https://pypi.python.org/pypi/traitsui/


自动检验




HasTraits的派生类用Trait属性保存数据,它相当于MVC模式中的模型(Model)。当没有指定界面显示方式时,Traits库会自动创建一个缺省的界面。我们可以通过视图(View)对象为模型设计更加实用的界面。

# -*- coding: utf-8 -*-#  Copyright (c) 2007, Enthought, Inc.#  License: BSD Style.from traits.api import HasTraits, Int, Strfrom traitsui.api import View, Itemclass Employee(HasTraits):    name = Str    department = Str    age = Int    classes = Int    view = View(         Item('department', label=u"年级", tooltip=u"班级所属年级"),         Item('name', label=u"姓名"),        Item('age', label=u"年龄"),        Item('classes', label=u"班级"),        title = u"学生资料", width=250, height=150, resizable=True     )if __name__ == "__main__":    p = Employee()    p.configure_traits()