在项中使用HasTraits对象时,从多个视图中选择

2024-06-15 05:50:56 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有办法为HasTraits对象定义多个视图,并在将它们显示为Item时选择它们?你知道吗

class Person(HasTraits):
    first_name = String()
    last_name = String()

    formal_view = View(
        Item('first_name'),
        Item('last_name'),
        )
    familiar_view = View(
        Item('first_name')
        )

class Family(HasTraits):
    formal_father = Instance(Person,())
    familiar_father = Instance(Person,())


    view = View(
        Item('formal_father', style = 'custom'),
        Item('familiar_father', style = 'custom', 
             view = 'familiar_view'),
        )

最后一项中的关键字view只是为了说明我希望它如何工作。你知道吗


Tags: instancenameviewstringstyleitemclassperson