Skip to content

Instantly share code, notes, and snippets.

@gottadiveintopython
Created February 23, 2025 08:10
Show Gist options
  • Save gottadiveintopython/afccb17cbb49033d6e6e4c76c6e1ffb1 to your computer and use it in GitHub Desktop.
Save gottadiveintopython/afccb17cbb49033d6e6e4c76c6e1ffb1 to your computer and use it in GitHub Desktop.
Kivyで文字列の描かれたTextureを作る。
from kivy.graphics.texture import Texture
from kivy.core.text import Label as CoreLabel
from kivy.core.text.markup import MarkupLabel as CoreMarkupLabel
def create_texture_from_text(*, markup=False, **label_kwargs) -> Texture:
'''
.. code-block::
from kivy.metrics import sp
texture = create_texture_from_text(
text='Hello',
font_size=sp(50),
font_name='Roboto',
color=(1, 0, 0, 1),
)
See :class:`kivy.core.text.LabelBase` for all the available keyword parameters.
'''
core_cls = CoreMarkupLabel if markup else CoreLabel
core = core_cls(**label_kwargs)
core.refresh()
return core.texture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment