【问题标题】:Kivy Button widget : Attribute Error, has no attribute 'fbind'Kivy 按钮小部件:属性错误,没有属性“fbind”
【发布时间】:2017-03-01 16:10:27
【问题描述】:

自两三个小时以来,我一直试图找到问题的解决方案,但我就是找不到问题所在,确切地说,即使在 SO 或 Kivy 文档中查看其他用户的问题时也是如此。

我目前正在网上学习一些教程,并开始玩弄this simple one

我的代码与他的不完全匹配,但即使在复制本教程的确切代码作为测试时,我也得到完全相同的错误,与 Kivy 中的 Button 小部件有关:

AttributeError: 'Button' object has no attribute 'fbind'

这可能与某种安装问题有关吗?谁能帮我解决这个问题?

[INFO              ] Kivy v1.8.0
[INFO              ] [Logger      ] Record log in C:\Users\NoirFluo\.kivy\logs\kivy_17-03-01_64.txt
[INFO              ] [Factory     ] 157 symbols loaded
[DEBUG             ] [Cache       ] register <kv.lang> with limit=None, timeout=Nones
[DEBUG             ] [Cache       ] register <kv.image> with limit=None, timeout=60s
[DEBUG             ] [Cache       ] register <kv.atlas> with limit=None, timeout=Nones
[INFO              ] [Image       ] Providers: img_tex, img_dds, img_pygame, img_pil, img_gif 
[DEBUG             ] [Cache       ] register <kv.texture> with limit=1000, timeout=60s
[DEBUG             ] [Cache       ] register <kv.shader> with limit=1000, timeout=3600s
[DEBUG             ] [App         ] Loading kv <C:/Users/NoirFluo/Desktop/Python/Kivy/TestProblemButton\screens.kv>
[DEBUG             ] [Window      ] Ignored <egl_rpi> (import error)
[INFO              ] [Window      ] Provider: pygame(['window_egl_rpi'] ignored)
[DEBUG             ] [Window      ] Display driver windib
[DEBUG             ] [Window      ] Actual window size: 800x600
[DEBUG             ] [Window      ] Actual color bits r8 g8 b8 a8
[DEBUG             ] [Window      ] Actual depth bits: 24
[DEBUG             ] [Window      ] Actual stencil bits: 8
[DEBUG             ] [Window      ] Actual multisampling samples: 2
[INFO              ] [GL          ] OpenGL version <4.5.13464 Compatibility Profile Context 21.19.407.0>
[INFO              ] [GL          ] OpenGL vendor <ATI Technologies Inc.>
[INFO              ] [GL          ] OpenGL renderer <AMD Radeon HD 7800 Series>
[INFO              ] [GL          ] OpenGL parsed version: 4, 5
[INFO              ] [GL          ] Shading version <4.50>
[INFO              ] [GL          ] Texture max size <16384>
[INFO              ] [GL          ] Texture max units <32>
[DEBUG             ] [Shader      ] Fragment compiled successfully
[DEBUG             ] [Shader      ] Vertex compiled successfully
[DEBUG             ] [ImagePygame ] Load <C:\Users\NoirFluo\Anaconda2\lib\site-packages\kivy\data\glsl\default.png>
[INFO              ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO              ] [Text        ] Provider: pygame
GLEW initialization succeeded

Traceback (most recent call last):

  File "<ipython-input-1-414e3aba4aa1>", line 1, in <module>
    runfile('C:/Users/NoirFluo/Desktop/Python/Kivy/TestProblemButton/main.py', wdir='C:/Users/NoirFluo/Desktop/Python/Kivy/TestProblemButton')

  File "C:\Users\NoirFluo\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
    execfile(filename, namespace)

  File "C:\Users\NoirFluo\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfile
    exec(compile(scripttext, filename, 'exec'), glob, loc)

  File "C:/Users/NoirFluo/Desktop/Python/Kivy/TestProblemButton/main.py", line 26, in <module>
    ScreensApp().run()

  File "C:\Users\NoirFluo\Anaconda2\lib\site-packages\kivy\app.py", line 766, in run
    root = self.build()

  File "C:/Users/NoirFluo/Desktop/Python/Kivy/TestProblemButton/main.py", line 23, in build
    return Manager()

  File "C:\Users\NoirFluo\Anaconda2\lib\site-packages\kivy\uix\screenmanager.py", line 791, in __init__
    super(ScreenManager, self).__init__(**kwargs)

  File "C:\Users\NoirFluo\Anaconda2\lib\site-packages\kivy\uix\floatlayout.py", line 66, in __init__
    super(FloatLayout, self).__init__(**kwargs)

  File "C:\Users\NoirFluo\Anaconda2\lib\site-packages\kivy\uix\layout.py", line 63, in __init__
    super(Layout, self).__init__(**kwargs)

  File "C:\Users\NoirFluo\Anaconda2\lib\site-packages\kivy\uix\widget.py", line 173, in __init__
    Builder.apply(self)

  File "C:\Users\NoirFluo\Anaconda2\lib\site-packages\kivy\lang.py", line 1566, in apply
    self._apply_rule(widget, rule, rule)

  File "C:\Users\NoirFluo\Anaconda2\lib\site-packages\kivy\lang.py", line 1672, in _apply_rule
    self.apply(child)

  File "C:\Users\NoirFluo\Anaconda2\lib\site-packages\kivy\lang.py", line 1566, in apply
    self._apply_rule(widget, rule, rule)

  File "C:\Users\NoirFluo\Anaconda2\lib\site-packages\kivy\lang.py", line 1670, in _apply_rule
    child = cls(__no_builder=True)

  File "C:\Users\NoirFluo\Anaconda2\lib\site-packages\kivy\uix\behaviors\button.py", line 83, in __init__
    self.fbind('state', self.cancel_event)

AttributeError: 'Button' object has no attribute 'fbind'`

这是screens.kv文件中的代码:

#:kivy 1.8.0

<ScreenOne>:
    Button:
        text: "On SCREEN 1 >> Go to Screen 2"
        on_press: root.manager.current = "screen2"

<ScreenTwo>:
    Button:
        text: "On SCREEN 2 >> Go to Screen 3"
        on_press: root.manager.current = "screen3"

<ScreenThree>:
    Button:
        text: "On SCREEN 3 >> Go to Screen 1"
        on_press: root.manager.current = "screen1"


<Manager>:
    id: screen_manager

    screen_one: screen_one
    screen_two: screen_two
    screen_three: screen_three

    ScreenOne:
        id: screen_one
        name: "screen1"
        manager: screen_manager

    ScreenTwo:
        id: screen_two
        name: "screen2"
        manager: screen_manager

    ScreenThree:
        id: screen_three
        name: "screen3"
        manager: screen_manager

这是 main.py 的代码:

# -*- coding: utf-8 -*-
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty

class ScreenThree(Screen):
    pass

class ScreenTwo(Screen):
    pass

class ScreenOne(Screen):
    pass

class Manager(ScreenManager):
    screen_one = ObjectProperty(None)
    screen_two = ObjectProperty(None)
    screen_three = ObjectProperty(None)

class ScreensApp(App):

    def build(self):
        return Manager()

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

编辑:嗯,编辑吃掉了我的“大家好!”,由于某些原因,我似乎无法通过编辑我的帖子来恢复它,所以我将它放在这里:大家好! ^^'

【问题讨论】:

  • 题外话了,但是你为什么用kivy 1.8.0呢?

标签: python python-2.7 kivy anaconda kivy-language


【解决方案1】:

Kivy 1.8.0 是一个恐龙,很快就会有一个比当前旧的稳定版 (1.9.1) 更新的版本。

我已经尝试过您的代码,它运行良好,而且我相信它甚至在 1.8.0 上也能正常运行(不确定,如果需要,请查看已关闭的 issues)。

现在您可以执行以下操作之一:

  • 从您要使用的标签中完全重新安装 Kivy 安装(如果是 1.8.0,那就去吧)

  • 安装稳定版

  • 安装最新的 Kivy 版本

查看instructions 了解如何操作,如果还不够或太难,请使用this installer。请注意,这 IS NOT! 与您现在拥有的 kivy.bat 相同(1.8.0 包中有这样的文件,现在不在这里了),所以它不能作为替换旧的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-23
    • 2018-09-01
    • 2016-11-12
    • 2016-05-01
    • 1970-01-01
    • 2016-10-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多