python - 为什么我似乎无法将标签放入 Kivy 应用程序中的 StackLayout(或其他布局)中?

标签 python kivy

理论上,放 Kivy- Label进入Stack Layout (或进入其他布局)应该是最简单和最常见的事情 - 但它目前让我陷入绝望。以下语法显示一个普通的单按钮应用程序(在 Kivy 1.8 或 1.9、Win 7 下)直到我取消注释标签生成行,该应用程序始终会失败并显示诸如 AttributeError: 'LabelPygame 之类的消息'对象没有属性'bind'AttributeError:'LabelSDL2'对象没有属性'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

关于python - 为什么我似乎无法将标签放入 Kivy 应用程序中的 StackLayout(或其他布局)中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30469218/

相关文章:

python - 获取在另一个终端中执行的 python 进程的状态

Python 对数组的每一列应用函数

python - Kivy 代码段错误

python - 使用 oAuth 的网站的 redirect_uri

python - 'app' 级别导入 django 1.4?

python - 在 scrapy 中返回第一个遇到的结果

python - 使用 pyfmi 库在 python 中加载 fmu 时出错

python - 如何在kivy python中使用 slider 作为进度条并控制音频?

python - 创建 Kivy 应用程序时我总是遇到此错误

python - 带有 Kivy 错误的 Pycharm [CRITICAL] [App] 无法获取窗口,中止