【问题标题】:How to get rid of Kivymd Hot reload Viewer Error如何摆脱 Kivymd Hot reload Viewer Error
【发布时间】: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


    【解决方案1】:

    pos_hint 应该是字典,但 {""} 不是合法字典。如果您想要一个空字典,请使用pos_hint: {}

    【讨论】:

      猜你喜欢
      • 2011-09-25
      • 2017-09-23
      • 1970-01-01
      • 1970-01-01
      • 2022-12-16
      • 2015-08-13
      • 1970-01-01
      • 2019-02-02
      • 2020-12-06
      相关资源
      最近更新 更多