OK, I’m clearly missing something here.
After doing some simple stuff like making buttons and labels etc. I decided to start using styles.
I thought I got the concept, but now I’m quite sure I don’t.
I copied the code to create a gauge. First from the examples directory, without style. This works perfectly.
But now this one. As soon as I run the program I get
AttributeError: 'module' object has no attribute 'style_plain'
And when i change to
style = lv.style_t()
I get:
AttributeError: 'lv_style_t' object has no attribute 'body'
So I tried typing help(lv.style_t), but then I see that this has only attributes with SET_ in front of it.
So the program is correct in stating that ‘style_plain’ is not an attribute, but where am I missing the point then?
import lvgl as lv
import lvesp32
# Import ILI9341 driver and initialize it
from ili9XXX import ili9341, LANDSCAPE
disp = ili9341(
mosi=23, cs=22, clk=18, dc=2, rst=21,
mhz=40,
factor=16,
hybrid=True,
rot=LANDSCAPE,
width=320,
height=240
)
# Import XPT2046 driver and initialize it
from xpt2046 import xpt2046
touch = xpt2046(
cs=14,
transpose=False,
cal_x0=3780,
cal_y0=252,
cal_x1=393,
cal_y1=3751
)
style = lv.style_t(lv.style_plain)
style.body.main_color = lv.color_hex3(0x666) # Line color at the beginning
style.body.grad_color = lv.color_hex3(0x666) # Line color at the end
style.body.padding.left = 10 # Scale line length
style.body.padding.inner = 8 # Scale label padding
style.body.border.color = lv.color_hex3(0x333) # Needle middle circle color
style.line.width = 3
style.text.color = lv.color_hex3(0x333)
style.line.color = lv.color_hex3(0xF00) # Line color after the critical value
# Describe the color for the needles
needle_colors = [
lv.color_make(0x00, 0x00, 0xFF),
lv.color_make(0xFF, 0xA5, 0x00),
lv.color_make(0x80, 0x00, 0x80)
]
homescr = lv.obj()
# Create a gauge
gauge1 = lv.gauge(homescr)
gauge1.set_style(lv.gauge.STYLE.MAIN, style)
gauge1.set_needle_count(len(needle_colors), needle_colors)
gauge1.set_size(150, 150)
gauge1.align(None, lv.ALIGN.CENTER, 0, 20)
# Set the values
gauge1.set_value(0, 10)
gauge1.set_value(1, 20)
gauge1.set_value(2, 30)
# Load the screen
lv.scr_load(homescr)