是否可以在 Traitsui 类中的视图之间切换?

发布于 2024-12-29 02:20:43 字数 718 浏览 3 评论 0原文

我正在用 Enthought 的 TraitsUI 用 python 编写一个 GUI 程序。我希望能够在同一对象的不同视图之间切换以响应用户的操作。可以这样做吗?

以下大致演示了我想要做的事情:

from enthought.traits.api import HasTraits, Button
from enthought.traits.ui.api import View, Item

class Test(HasTraits):
    button1 = Button('Button 1')
    button2 = Button('Button 2')
    button3 = Button('Button 3')

    traits_view = View(Item('button1'), Item('button2'))
    view2 = View(Item('button1'), Item('button3'))

    def _button1_fired(self):
        #select view2
        pass

    def _button3_fired(self):
        #select traits_view
        pass

if __name__ == "__main__":
    test = Test()
    test.configure_traits()

I'm writing a GUI program in python with TraitsUI from Enthought. I want to be able to switch between different Views of the same object in response to a user's action. Is it possible to do that?

The following approximately demonstrates what I want to do:

from enthought.traits.api import HasTraits, Button
from enthought.traits.ui.api import View, Item

class Test(HasTraits):
    button1 = Button('Button 1')
    button2 = Button('Button 2')
    button3 = Button('Button 3')

    traits_view = View(Item('button1'), Item('button2'))
    view2 = View(Item('button1'), Item('button3'))

    def _button1_fired(self):
        #select view2
        pass

    def _button3_fired(self):
        #select traits_view
        pass

if __name__ == "__main__":
    test = Test()
    test.configure_traits()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鯉魚旗 2025-01-05 02:20:43

也许您可以不通过切换视图来实现您想要的效果,而是通过在作为视图一部分的组的定义中使用visible_when关键字来实现。例子中有一些启发:
示例/demo/Dynamic_Forms/visible_when.py

Maybe you can achieve the effect you desire not by switching views but by use of the visible_when keyword in the definition of a Group that's part of your view. There is some inspiration in the examples:
examples/demo/Dynamic_Forms/visible_when.py

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文