Group Box Example

An example of the GroupBox widget.

A GroupBox is a simple subclass of Container which draws itself with an optional bounding box and title.

Tip

To see this example in action, download it from group_box and run:

$ enaml-run group_box.enaml

Screenshot

../_images/ex_group_box.png

Example Enaml Code

#------------------------------------------------------------------------------
# Copyright (c) 2013, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
""" An example of the `GroupBox` widget.

A `GroupBox` is a simple subclass of `Container` which draws itself with
an optional bounding box and title.

<< autodoc-me >>
"""
from __future__ import print_function
from enaml.layout.api import vbox, hbox, spacer, align
from enaml.widgets.api import (
    Window, Container, GroupBox, Form, Label, Field, CheckBox, ComboBox,
    MultilineField, PushButton,
)


enamldef Main(Window):
    title = "Group Boxes"
    Container:
        constraints = [
            vbox(
                grp_box,
                hbox(push, spacer, title_check, flat_check, combo_box),
                multiline,
            ),
            align('v_center', title_check, flat_check, combo_box),
        ]
        GroupBox: grp_box:
            title << "Personal Details" if title_check.checked else ""
            title_align << combo_box.items[combo_box.index]
            Form:
                Label:
                    text = "First name:"
                Field:
                    pass
                Label:
                    text = "Last name:"
                Field:
                    pass
                Label:
                    text = "Home phone:"
                Field:
                    pass
        CheckBox: title_check:
            text = "Show Title"
            checked = True
        CheckBox: flat_check:
            text = "Flat"
            checked := grp_box.flat
        PushButton: push:
            text = "Submit"
            clicked ::
                print('Submit')
                print(multiline.text)
        ComboBox: combo_box:
            index = 0
            items = ['left', 'center', 'right']
        MultilineField: multiline:
            pass