Colors: css & themes

# Jump directly to Examples

Colors: css & themes

Currently, the default css is included in this file. You can easily extend the default style by create a css file in your ~/.pymt/user.css.

Exemple of user.css

* {
    /* increase the font-size of every widget */
    font-size: 18;
}

Warning

Only class name of widget is currently use to search CSS.

We cannot describe how to style every widget in this class. If you want to known which attribute is needed to style a widget, please look on the widget documentation.

pymt.ui.colors.css_get_style(widget)

Return a dict() with all the style for the widget.

Parameters :
widget: class

Widget to search CSS

pymt.ui.colors.get_truncated_classname(name)

Return the css-ized name of a class (remove the MT prefix, and all in lowercase)

pymt.ui.colors.pymt_sheet

Instance of the CSS sheet

pymt.ui.colors.css_add_sheet(text, _reload=False)

Add a css text to use. Example

mycss = '#buttonA { bg-color: rgba(255, 127, 0, 127); }'
css_add_sheet(mycss)
pymt.ui.colors.css_add_file(cssfile, _reload=False)

Add a css file to use. Adds all the css rules in the given file to the pymt css rule set being used

css_add_sheet(cssfile)
pymt.ui.colors.css_get_widget_id(widget)

Return the css id of a widget

pymt.ui.colors.css_register_state(name)

Register a new state

pymt.ui.colors.css_add_keyword(keyword, convertfunc)

Add a new keyword to be autoconverted when reading CSS. Convert function can be found in parser.py

pymt.ui.colors.css_register_prefix(name)

Register a new prefix

Examples

File ui_colors_cssreload.py

from pymt import *

css_add_file('reload.css')

b1 = MTButton(id='btn1', label='Reload CSS', pos=(100, 100))
b2 = MTButton(id='btn2', label='Button 2', pos=(250, 100))

@b1.event
def on_press(*largs):
    css_reload()

w = getWindow()
w.add_widget(b1)
w.add_widget(b2)

runTouchApp()

Table Of Contents

Previous topic

Animation package: handle animation with ease in PyMT

Next topic

Factory: all widgets are registered through this factory

This Page