kivymd / KivyMD

KivyMD is a collection of Material Design compliant widgets for use with Kivy, a framework for cross-platform, touch-enabled graphical applications. https://youtube.com/c/KivyMD https://twitter.com/KivyMD https://habr.com/ru/users/kivymd https://stackoverflow.com/tags/kivymd
https://kivymd.readthedocs.io
MIT License
2.25k stars 674 forks source link

MDTextField setting font_name does not take effect, how to solve it? #1751

Closed yeyuchen198 closed 2 days ago

yeyuchen198 commented 5 days ago

Description of the Bug

MDTextField setting font_name does not take effect, how to solve it?

Judging from my own testing, the font_name setting of the MDTextField sub-control MDTextFieldHintText is effective and can indeed display Chinese, but the font_name setting of the MDTextField itself does not seem to be effective?

In my sample code: print(text_field.font_name), get the result: Roboto print(text_field.children[0].font_name), get the result: ChineseFont

How can I make the custom font_name set by MDTextField take effect?

Code and Logs

from kivy.core.text import LabelBase
from kivymd.app import MDApp
from kivymd.uix.textfield import MDTextField, MDTextFieldHintText

class MyApp(MDApp):
    def build(self):
        LabelBase.register(name="ChineseFont", fn_regular="assets/simhei.ttf")
        self.theme_cls.theme_style = "Dark"
        self.theme_cls.primary_palette = "Blue"

        text_field = MDTextField(
            MDTextFieldHintText(
                text="Hint text 请输入搜索关键词",
                theme_font_name='Custom',
                font_name="ChineseFont",
            ),
            mode="outlined",
            size_hint_x=None,
            width="360dp",
            pos_hint={"center_x": 0.5, "center_y": 0.5},
            theme_font_name='Custom',
            font_name="ChineseFont",
        )
        print(text_field.font_name)
        print(text_field.children[0].font_name)

        return text_field

if __name__ == "__main__":
    MyApp().run()

Screenshots

Add images to explain us this bug. Paste urls here.

image image

Versions

yeyuchen198 commented 2 days ago

不知道改了哪里,又可以了 it working now image

yeyuchen198 commented 2 days ago

sovled