为什么我似乎不能将标签放入Kivy-App中的StackLayout(或其他布局)中?



理论上,在堆栈布局(或其他布局)中放置一个Kivy-Label应该是最简单和最常见的事情-但它目前让我陷入绝望。下面的语法显示一个普通的单按钮应用程序(在Kivy 1.8或1.9,Win 7下),直到我取消注释标签生成行,这始终失败的消息,如AttributeError: 'LabelPygame' object has no attribute 'bind'AttributeError: 'LabelSDL2' object has no attribute 'bind'(在layout.py):

from kivy.app import App
from kivy.uix.button import Button
from kivy.core.text import Label
from kivy.uix.stacklayout import StackLayout
class TestApp(App):
    def build(self):
        mylayout = StackLayout(orientation='lr-tb')
        mylayout.add_widget(Button(text='This button can always be rendered.'))
        # mylayout.add_widget(Label(text='This label seems to cause trouble.'))
        return mylayout
TestApp().run()

我有一种预感,我忽视了一些非常非常明显或愚蠢的东西,但不知道它是什么。基于BuilderrunTouchApp的另一种调用似乎工作得很好(布局的类型似乎没有影响):

# ... other imports abbreviated ... 
Builder.load_string('''
<MyLayout>:
    Button:
        text: "This button can always be rendered."
    Label:
        text: "This label works in this case."
''')
class MyLayout(FloatLayout):
    pass
runTouchApp(MyLayout())

您正在导入kivy.core.text.Label,但您真正需要的是kivy.uix.label.Label

最新更新