Button package: implement different type of button
Bases: pymt.ui.widgets.label.MTLabel
MTButton is a button implementation using MTLabel
| Parameters : |
|
|---|---|
| Styles : | Note All the css attributes can be postfixed with the state of the button. It will only work with attributes used for background. For example `bg-color` for normal state
`bg-color-down` for down state
|
| Events : |
|
Sets the state of the button, “normal” or “down”
Bases: pymt.ui.widgets.button.MTButton
Toggle button implementation, based on MTButton
| Parameters : |
|
|---|
Return all widgets selected in a group
Return all widgets in a group
Return the group of a toggle button
Bases: pymt.ui.widgets.button.MTButton
MTImageButton is a enhanced MTButton that draw an image instead of a text.
| Parameters : |
|
|---|
File ui_widgets_button_align.py
from pymt import *
w = MTWidget()
y = 0
for halign in ('left', 'center', 'right'):
y += 100
x = 100
for valign in ('top', 'center', 'bottom'):
m = MTButton(label='%s:%s' % (halign, valign),
pos=(x, y), size=(150, 30),
anchor_x=halign, anchor_y=valign)
x += 200
w.add_widget(m)
runTouchApp(w)
from pymt import *
# Create a CSS with 2 rules
additional_css = '''
.simple {
draw-alpha-background: 0;
draw-border: 0;
draw-text-shadow: 1;
}
.colored {
bg-color: rgb(68, 170, 0);
border-radius: 20;
border-radius-precision: .1;
font-size: 16;
}
'''
# Add the CSS into PyMT
css_add_sheet(additional_css)
# Create different button, with one or 2 rules at the same time
v = MTBoxLayout(orientation='vertical', padding=20, spacing=20)
v.add_widget(MTButton(label='Coucou'))
v.add_widget(MTButton(label='Coucou', cls='simple'))
v.add_widget(MTButton(label='Coucou', cls='colored'))
v.add_widget(MTButton(label='Coucou', cls=('simple', 'colored')))
runTouchApp(v)
File ui_widgets_button_toggle.py
from pymt import *
b = MTToggleButton(label='Push me')
@b.event
def on_press(*largs):
print 'on_press()', b.state, largs
@b.event
def on_release(*largs):
print 'on_release()', b.state, largs
runTouchApp(b)
File ui_widgets_button.py
'''
Button example with all events in button.
'''
from pymt import *
b = MTButton(label='Push me')
@b.event
def on_press(*largs):
print 'on_press()', b.state, largs
@b.event
def on_release(*largs):
print 'on_release()', b.state, largs
@b.event
def on_state_change(*largs):
print 'on_state_change()', b.state, largs
runTouchApp(b)
File ui_widgets_buttonmatrix.py
from pymt import *
# create a custom 10x10 matrix, fullscreen
m = MTButtonMatrix(matrix_size=(10, 10), size_hint=(1, 1))
# create a default handler for the on_press event
def m_on_press(args):
# extract row / column / state
row, column, state = args
print 'matrix change at %d x %d = %s' % (row, column, state)
# connect the handler to the widget
m.connect('on_press', m_on_press)
runTouchApp(m)