【发布时间】:2021-04-19 04:32:11
【问题描述】:
我正在测试 Kivymd 热重载。它运行良好,但是当我输入 pos_hint: {""} 时,Kivy 给了我一个错误。
代码(此代码来自 Kivymd 文档):
from kivy.lang import Builder
from kivymd.app import MDApp
KV = '''
#:import KivyLexer kivy.extras.highlight.KivyLexer
#:import HotReloadViewer kivymd.utils.hot_reload_viewer.HotReloadViewer
BoxLayout:
CodeInput:
lexer: KivyLexer()
style_name: "native"
on_text: app.update_kv_file(self.text)
size_hint_x: .6
HotReloadViewer:
size_hint_x: .4
path: app.path_to_kv_file
errors: True
errors_text_color: 1, 0, 0, 1
errors_background_color: app.theme_cls.bg_light
'''
class Example(MDApp):
path_to_kv_file = "kv_file.kv"
def build(self):
self.theme_cls.theme_style = "Light"
return Builder.load_string(KV)
def update_kv_file(self, text):
with open(self.path_to_kv_file, "w") as kv_file:
kv_file.write(text)
Example().run()
错误:
AttributeError: 'str' object has no attribute 'items'
为什么会出现这个错误以及如何解决这个错误?
我使用的是 Python 3.8。谢谢
【问题讨论】:
标签: kivy python-3.8 kivymd hot-reload