enaml

How to set the background color of an enaml window?


I am trying to use enaml for creating the view for my application. I would like to know how to set the background color of the Window widget. I see that I can use a stylesheet for setting colors for things that are inside the window, but I can't seem to find a way to set the color of the window.

enamldef Main(MainWindow):
StyleSheet:
    Style:
        element = 'PushButton'

        Setter:
            field = 'background'
            value = 'indianred'

title << ""
initial_size = (1000,500)
initial_position = (300,150)
icon = loadIcon(normpath('TitleIcon.png'))
visible = True
always_on_top = True
style_class << "WindowStyle"

MyMenuBar:
    pass

Container:
    #constraints = [vbox(label, label, spacing=0)]
    PushButton:
        text = "one"
    pass

Solution

  • You just have to style the correct element:

    enamldef Main(MainWindow):
        StyleSheet:
            Style:
                element = 'Main'
                Setter:
                    field = 'background'
                    value = 'indianred'
        Container:
            PushButton:
                text = "one"
    

    Example Screenshot