问题
Im trying to learn KivyMD tools. So i created MDToolBar and it's title changes after some button clicks. Im trying to optimize it's text_size but can't do it.I already tried font_type:'H1', font_size: '8sp'. Also i want to change it's font if its possible. Can anyone help me about that. Im sharing minimal code below:
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()
回答1:
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()
来源:https://stackoverflow.com/questions/63367111/kivymd-how-to-change-mdtoolbar-title-size-and-font