kivy字体全局更换,并使用自定义的config.ini文件
import os
from kivy.config import Config
from configparser import ConfigParser
current_directory = os.path.dirname(os.path.abspath(__file__))
my_font = os.path.join(current_directory, "myfont.ttf")
config_path = os.path.join(current_directory, "config.ini")
config = ConfigParser()
config.read(config_path, encoding = 'UTF-8')
config.set('kivy', 'default_font', str(['myfont',my_font]))
with open(config_path, 'w') as configfile:
config.write(configfile)
Config.read(config_path)
注意:config.ini的加载,必须放在kivy相关模块的导入之前!!!