1def draw_part_event_cb(e):
2    obj = e.get_target()
3    dsc = lv.obj_draw_part_dsc_t.__cast__(e.get_param())
4    # If the cells are drawn../
5    if dsc.part == lv.PART.ITEMS:
6        row = dsc.id //  obj.get_col_cnt()
7        col = dsc.id - row * obj.get_col_cnt()
8
9        # Make the texts in the first cell center aligned
10        if row == 0:
11            dsc.label_dsc.align = lv.TEXT_ALIGN.CENTER
12            dsc.rect_dsc.bg_color = lv.palette_main(lv.PALETTE.BLUE).color_mix(dsc.rect_dsc.bg_color, lv.OPA._20)
13            dsc.rect_dsc.bg_opa = lv.OPA.COVER
14
15        # In the first column align the texts to the right
16        elif col == 0:
17            dsc.label_dsc.flag = lv.TEXT_ALIGN.RIGHT
18
19        # Make every 2nd row grayish
20        if row != 0 and (row % 2) == 0:
21            dsc.rect_dsc.bg_color = lv.palette_main(lv.PALETTE.GREY).color_mix(dsc.rect_dsc.bg_color, lv.OPA._10)
22            dsc.rect_dsc.bg_opa = lv.OPA.COVER
23
24
25table = lv.table(lv.scr_act())
26
27# Fill the first column
28table.set_cell_value(0, 0, "Name")
29table.set_cell_value(1, 0, "Apple")
30table.set_cell_value(2, 0, "Banana")
31table.set_cell_value(3, 0, "Lemon")
32table.set_cell_value(4, 0, "Grape")
33table.set_cell_value(5, 0, "Melon")
34table.set_cell_value(6, 0, "Peach")
35table.set_cell_value(7, 0, "Nuts")
36
37# Fill the second column
38table.set_cell_value(0, 1, "Price")
39table.set_cell_value(1, 1, "$7")
40table.set_cell_value(2, 1, "$4")
41table.set_cell_value(3, 1, "$6")
42table.set_cell_value(4, 1, "$2")
43table.set_cell_value(5, 1, "$5")
44table.set_cell_value(6, 1, "$1")
45table.set_cell_value(7, 1, "$9")
46
47# Set a smaller height to the table. It'll make it scrollable
48table.set_height(200)
49table.center()
50
51# Add an event callback to apply some custom drawing
52table.add_event_cb(draw_part_event_cb, lv.EVENT.DRAW_PART_BEGIN, None)
53
54