Question

I am just starting out with TraitsUI, and I am beginner Python programmer. I hope this question is not too low-level.

I want to display a button set up in ControlPanel, calling it from Main. When i do the following, i just a window with a button that says "Panel". If I click that button, i get another window with the "Start" button I want. How do i just get the window with the Start button?

Thanks, Cosmo

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() 
Was it helpful?

Solution

In MainWindow, change this:

    view = View(Item('panel'))

to this:

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

See the InstanceEditor() documentation for more information. The relevant part of that document is the paragraph below the screenshot. The simple style for an InstanceEditor (which is the default style) creates a button that when clicked opens up a new window containing a view of the instance. The custom style embeds the view of the instance in the same window that contains the item. The screenshot in Fig. 36 shows an example. The top of the screenshot shows the simple style, and below that is the custom style. (And below that are the text and readonly styles, but they are not very useful except perhaps for debugging.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top