我正在尝试学习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()
答案 0 :(得分:0)
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()