kivy Config.get导致NoSecionError

时间:2016-12-11 18:26:23

标签: python kivy

我尝试使用customm部分设置一些配置属性。然后,当我想读取属性时,我得到一个NoSectionError。以下示例是绝对基本的,可能没有这种意义。但我需要在build方法中读取配置。

使用的版本:

  • Python 2.7
  • kivy 1.9.1

实施例

class MyTestApp(App):
    def build(self):
        Config.get('user_settings', 'strategy1')
        return FloatLayout()

    def build_config(self, config):
        config.setdefaults('user_settings',
                           {
                               'strategy1': 'example',
                               'strategy2': 'example'
                           })

MyTestApp().run()

导致以下异常:

 Traceback (most recent call last):
   File "test/main.py", line 59, in <module>
     MyTestApp().run()
   File "C:\Python27\lib\site-packages\kivy\app.py", line 802, in run
     root = self.build()
   File "test/main.py", line 17, in build
     Config.get('user_settings', 'strategy1')
   File "C:\Python27\lib\site-packages\kivy\config.py", line 433, in get
     value = PythonConfigParser.get(self, section, option, **kwargs)
   File "C:\Python27\lib\ConfigParser.py", line 607, in get
     raise NoSectionError(section)
 ConfigParser.NoSectionError: No section: 'user_settings'

1 个答案:

答案 0 :(得分:0)

在应用内,您必须使用self.config代替Config