所以我的traitsUI代码有问题。我想要的是一个使用CheckListEditor()显示的List,它位于一个受限制的空间中,因此它可以滚动。我需要将这个List放在一个组中,因为这只是整个GUI的一小部分。然而,如果我设置Group属性"可滚动" to" True"什么都不做。有任何想法吗? 这是最小的工作示例:
from traits.api import HasTraits, List
from traitsui.api import View, ListEditor, Group, Item, CheckListEditor, Group
class Foo(HasTraits):
my_list = List()
full_list = List()
def _full_list_default(self):
return [str(n) for n in range(10)]
traits_view = View(Group(Item('my_list',
style='custom',
editor=CheckListEditor(name = 'full_list')),
scrollable = True,
orientation = 'vertical'),
height=100)
if __name__ == '__main__':
f = Foo()
f.configure_traits()
答案 0 :(得分:0)
应该可以滚动View
:
from traits.api import HasTraits, List
from traitsui.api import (
View, ListEditor, Group, Item, CheckListEditor, Group
)
class Foo(HasTraits):
my_list = List()
full_list = List()
def _full_list_default(self):
return [str(n) for n in range(10)]
traits_view = View(Group(Item('my_list',
style='custom',
editor=CheckListEditor(name='full_list')),
orientation='vertical'),
scrollable=True,
height=100)
if __name__ == '__main__':
f = Foo()
f.configure_traits()
如果您要嵌入多个可滚动视图,可以使用Instance
和InstanceEditors
执行此操作:
from traits.api import HasTraits, List, Instance
from traitsui.api import (
View, ListEditor, Group,InstanceEditor, Item, CheckListEditor, Group,
VGroup
)
class Foo(HasTraits):
my_list = List()
full_list = List()
def _full_list_default(self):
return [str(n) for n in range(10)]
traits_view = View(Group(Item('my_list',
style='custom',
editor=CheckListEditor(name='full_list')),
orientation='vertical'),
scrollable=True,
height=100)
class FooContainingView(HasTraits):
foo_1 = Instance(Foo)
foo_2 = Instance(Foo)
traits_view = View(
VGroup(
Item('foo_1',
editor=InstanceEditor(),
style='custom',
show_label=False,
),
Item('foo_2',
editor=InstanceEditor(),
style='custom',
show_label=False,
),
),
resizable=True,
)
if __name__ == '__main__':
f = Foo()
fcv = FooContainingView(foo_1=Foo(), foo_2=Foo())
fcv.configure_traits()
......结果如下: