当一个对象作为实例从另一段代码中调用时,如何显示该对象

2024-06-07 11:26:20 发布

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

我刚从TraitsUI开始,我是Python程序员的初学者。希望这个问题不要太低级。你知道吗

我想在控制面板上显示一个按钮,从Main调用它。当我做下面的操作时,我只看到一个窗口,上面有一个按钮,上面写着“Panel”。如果我点击那个按钮,我会得到另一个窗口,上面有我想要的“开始”按钮。我怎么用“开始”按钮打开窗口?你知道吗

谢谢你, 宇宙

主要内容: 你知道吗

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() 

Tags: andthefromimportviewapi按钮start
1条回答
网友
1楼 · 发布于 2024-06-07 11:26:20

MainWindow中,更改以下内容:

    view = View(Item('panel'))

对此:

    view = View(Item('panel', style='custom'))

有关详细信息,请参阅InstanceEditor()文档。该文件的相关部分是屏幕截图下面的段落。InstanceEditorsimple样式(这是默认样式)创建一个按钮,单击该按钮将打开一个包含实例视图的新窗口。custom样式将实例的视图嵌入到包含该项的同一窗口中。图36中的屏幕截图示出了一个示例。屏幕截图的顶部显示了simple样式,下面是custom样式。(下面是textreadonly样式,但是除了调试之外,它们不是很有用。)

相关问题 更多 >

    热门问题