Created
February 23, 2025 08:10
-
-
Save gottadiveintopython/afccb17cbb49033d6e6e4c76c6e1ffb1 to your computer and use it in GitHub Desktop.
Kivyで文字列の描かれたTextureを作る。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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