尝试在Kivy中创建“IconButton”时出现FactoryException

时间:2015-09-16 12:43:47

标签: python kivy

我试图创建一个可以单击的图标,这意味着带有ButtonBehavior.I的图像跟随文档(http://kivy.org/docs/api-kivy.uix.behaviors.html),我有一个带有以下代码的FactoryException:

# coding: utf-8

from kivy.uix.behaviors import ButtonBehavior
from kivy.core.image import Image
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.lang import Builder


kv_string = """
BoxLayout:
    IconButton
"""


class IconButton(ButtonBehavior, Image):
    def on_press(self):
        print("on_press")


class DashboardApp(App):
    pass


Builder.load_string(kv_string)


if __name__ == "__main__":
    DashboardApp().run()

当我将IconButton的父类从(ButtonBehavior,Image)更改为(ButtonBehavior,Widget)时,问题就消失了。

1 个答案:

答案 0 :(得分:1)

您需要kivy.uix.image,而不是kivy.core.image