【问题标题】:AssertionError - KivyAssertionError - Kivy
【发布时间】:2020-05-12 00:03:13
【问题描述】:

我对 Python 和 Kivy 还很陌生。我正在尝试编写一个 Python (3.7) 程序来创建 Kivy (1.11.1) 显示并每 30 分钟更新一次信息。我遇到了 2 个我无法弄清楚的问题。

  1. 我在创建 Kivy 显示时收到 AssertionError。

    文件“C:\Users\user\Anaconda3\lib\site-packages\kivy\lang\builder.py”,第 554 行,在 _apply_rule 断言(规则不在 self.rulectx 中)

    断言错误

  2. 我收到一条警告,提示我的 Kivy 语言文件已多次加载

我将我的程序简化为仍然会导致错误和警告的基本信息:

from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ObjectProperty

class TheBox(FloatLayout):
    Day3 = ObjectProperty()
    Day2 = ObjectProperty()
    LastUpdate = ObjectProperty()

    def updateData(self):
        self.Day3.text = SE_days[0]
        self.Day2.text = SE_days[1]
        self.LastUpdate.text = 'Last Updated at: ' + SO_lastUpdate        

timeInterval = 30 #minutes
SE_days = ['4/3', '4/4']
SO_lastUpdate = '4/5 1:31 PM'

class DisplayTestApp(App):

    def build(self):
        x = TheBox()
        x.updateData()
        Clock.schedule_interval(x.update, timeInterval*60)
        return TheBox()

if __name__ == '__main__':
    DisplayTestApp().run()

还有我的 Kivy 语言文件:

#:kivy 1.11.1

<TheBox>:
    FloatLayout:
        FloatLayout:
            Label:
                id: Day3
                size_hint: .4, .1
                font_size: '24sp'
                color: (1, 1, 1)
                halign: 'right'
                pos_hint: {'right': .45, 'center_y': .5}
                text:
            Label:
                id: Day2
                size_hint: .4, .1
                font_size: '24sp'
                color: (1, 1, 1)
                halign: 'right'
                pos_hint: {'right': .45, 'center_y': .3}
                text:
        FloatLayout:
            Label:
                id: LastUpdate
                size_hint: .9, .2
                pos_hint: {'center_x': .5, 'center_y': .3}
                font_size: '18sp'
                color: (1, 1, 1)
                halign: 'center'
                text:

我做错了什么?

【问题讨论】:

    标签: python-3.x kivy kivy-language


    【解决方案1】:

    没关系...

    显然我在使用 Spyder/Anaconda 时遇到了问题。我重新启动了 IDE,AssertionError 和警告都消失了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-13
      • 2022-01-21
      • 2011-02-02
      相关资源
      最近更新 更多