我试图找到问题的解决方案,因为两三个小时,但我确实无法找到问题,确切地说,即使在这里查看其他用户的问题时也是如此在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()
编辑:嗯,编辑已经吃掉了我的&#34;你好,伙计们!&#34;,由于某些原因,我似乎无法通过编辑我的帖子来回复它,所以我&#39把它放在这里:大家好! ^^&#39;
答案 0 :(得分:1)
Kivy 1.8.0是恐龙,很快就会出现比当前老版本更稳定的版本(1.9.1)。
我已经尝试过你的代码并且它工作正常,我相信它甚至可以在1.8.0上运行而没有问题(不确定,如果你愿意,请查看关闭issues。)
现在您可以执行以下操作之一:
从您要使用的标签中完全重新安装您的Kivy安装(如果它是1.8.0,那就去吧)
安装稳定版
安装最新的Kivy版
检查instructions如何操作,如果不够或太难,请使用this installer。请注意,这个不是!与你现在拥有的kivy.bat
相同(1.8.0包中有这样的文件,它不再在这里),所以它不会作为旧的替代品。