我刚开始使用 TraitsUI,我是 Python 初学者。我希望这个问题不要太低级。
我想显示在 ControlPanel 中设置的按钮,从 Main 调用它。当我执行以下操作时,我只是一个带有“面板”按钮的窗口。如果我单击该按钮,我会得到另一个带有我想要的“开始”按钮的窗口。我如何才能获得带有“开始”按钮的窗口?
谢谢,科斯莫
主要的:
from enthought.traits.api import *
from enthought.traits.ui.api import *
class ControlPanel(HasTraits):
""" This object is the core of the traitsUI interface. It hosts the method for
interaction between the objects and the GUI.
"""
start = Button("Start Measurements")
view = View(Item('start', show_label=False, style='custom' ))
class MainWindow(HasTraits):
""" The main window, here go the instructions to create and destroy the application. """
panel = Instance(ControlPanel)
def _panel_default(self):
return ControlPanel()
view = View(Item('panel'))
if __name__ == '__main__':
MainWindow().configure_traits()