Button matrix: a lightweight and optimized grid of buttons

# Jump directly to Examples

Button matrix: a lightweight and optimized grid of buttons

class pymt.ui.widgets.buttonmatrix.MTButtonMatrix(**kwargs)

Bases: pymt.ui.widgets.widget.MTWidget

ButtonMatrix is a lightweight Grid of buttons/tiles
collide_point returns which matrix element was hit draw_tile(i,j) draws the tile @ matrix position (i,j)
Parameters :
matrix_size : tuple, default to (3, 3)

Matrix size

border : int, default to 5

Size of border

buttoncolor : color, default to (.2, .2, .2, 1)

Color of background

downcolor : color, default to (0, .5, 1, 1)

Color when the button is pushed

Events :
on_value_change (matrix)

Returns the whole matrix and a button is touched

on_press (row,column,state)

Returns the state and cell position of a button when touched

matrix_size

Return size of matrix

Examples

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)