2

我正在尝试学习 KivyMD 工具。所以我创建了 MDToolBar,它的标题在单击一些按钮后发生了变化。我试图优化它的 text_size 但做不到。我已经尝试过font_type:'H1'font_size: '8sp'。如果可能的话,我也想改变它的字体。任何人都可以帮我解决这个问题。我在下面分享最少的代码:

from kivy.lang import Builder
from kivy.uix.screenmanager import Screen,ScreenManager
kv = Builder.load_string("""
<SM>:
    P1:
<P1>:
    BoxLayout:
        orientation: 'vertical'
        MDToolbar:
            title: 'TEST'
            font_size: '50sp'
            font_name: 'font1.ttf'
""")
class P1(Screen):
    pass
class SM(ScreenManager):
    pass
class MyApp(MDApp):
    def build(self):
        return SM()
if __name__ == '__main__':
    MyApp().run()

4

1 回答 1

2
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen, ScreenManager

from kivymd.app import MDApp

kv = Builder.load_string(
    """
<SM>
    P1:


<P1>

    BoxLayout:
        orientation: 'vertical'

        MDToolbar:
            id: toolbar
            title: 'TEST'
""")


class P1(Screen):
    def __init__(self, **kw):
        super().__init__(**kw)
        Clock.schedule_once(self.set_toolbar_font_name)
        Clock.schedule_once(self.set_toolbar_font_size)

    def set_toolbar_font_name(self, *args):
        self.ids.toolbar.ids.label_title.font_name = "JetBrainsMono-ExtraBold-Italic.ttf"

    def set_toolbar_font_size(self, *args):
        self.ids.toolbar.ids.label_title.font_size = '50sp'


class SM(ScreenManager):
    pass


class MyApp(MDApp):
    def build(self):
        return SM()


if __name__ == '__main__':
    MyApp().run()
于 2020-08-11T23:29:17.023 回答