I would like to find the length of a string in pixels using KIVY, for the default or a specified font and size.
I found a similar question, How to calculate length of string in pixels for specific font and size? with a solution using PIL, which I could not make work:
from PIL import ImageFont
font = ImageFont.truetype('times.ttf', 12)
size = font.getsize('Hello world')
print(size)
How can I make the snippet above or something similar work using the cross-platform KIVY API?
I looked in the kivy metrics (https://kivy.org/doc/stable/api-kivy.metrics.html) and core.text docs (https://kivy.org/doc/stable/api-kivy.core.text.html), which have relevant methods, but I could not find what I needed.
based on the comment below from @johnAnderson, I tried the following, but I am getting a segmentation fault:
from kivy.core.text import Label as CoreLabel
my_label = CoreLabel()
my_label.text = 'hello'
my_label.refresh()
hello_texture = my_label.texture
print(hello_texture.text_size())
Any pointers would be appreciated. Thanks