This Page

HboxEqualWidths ExampleΒΆ

hbox_equal_widths.enaml

#------------------------------------------------------------------------------
#  Copyright (c) 2012, Enthought, Inc.
#  All rights reserved.
#------------------------------------------------------------------------------
""" An example which demonstrates the use of the `hbox` layout helper
along with some auxiliary constraints.

This example is nearly identical to the `hbox.enaml` example. However,
this time we add some auxiliary constraints to make the buttons equal
widths. When resizing the window, each button is therefore guaranteed
to expand by the same amount.

"""
from enaml.layout.api import hbox
from enaml.widgets.api import Window, Container, PushButton


enamldef Main(Window):
    Container:
        constraints = [
            hbox(pb1, pb2, pb3),
            pb1.width == pb2.width,
            pb2.width == pb3.width,
        ]
        PushButton:
            id: pb1
            text = 'Spam'
        PushButton:
            id: pb2
            text = 'Long Name Foo'
        PushButton:
            id: pb3
            text = 'Bar'

$ enaml-run hbox_equal_widths.enaml
../_images/hbox_equal_widths.png