【问题标题】:Blank white screen when running kivyMD app. No compiler errors运行 kivyMD 应用程序时出现空白屏幕。没有编译器错误
【发布时间】:2022-12-29 22:58:12
【问题描述】:

所以我是 kivyMD 的新手,正在尝试用它来开发移动应用程序。我正在尝试运行一个简单的脚本,该脚本将具有 kivyMD 中使用的各种类型的按钮。我正在使用 kitchensink 演示来尝试了解框架内的所有内容是如何工作的。但是,当我运行我的脚本时,终端中没有出现编译器错误,并且应用程序打开了,但它是一个空白的白屏。我不知道如何解决这个问题,因为我无法有效地诊断问题。有人有什么想法吗?

在 main.py 文件中

from kivy.lang import Builder
from kivymd.app import MDApp

class MainApp(MDApp):
    def build(self):
        pass


if __name__ == '__main__':
    app = MainApp()
    app.run()

在 main.kv 文件中:

MDScreen:

    MDFlatButton:
        text: 'MDFlatButton'
        pos_hint: {'center_x': 0.5, 'center_y': 0.9}

    MDRaisedButton:
        text: 'MDRaisedButton'
        pos_hint: {'center_x': 0.5, 'center_y': 0.8}

    MDRectangleFlatButton:
        text: 'MDRectangleFlatButton'
        pos_hint: {'center_x': 0.5, 'center_y': 0.7}

    MDRectangleFlatIconButton:
        icon: 'language-python'
        text: 'MDRectangleFlatIconButton'
        pos_hint: {'center_x': 0.5, 'center_y': 0.6}

    MDRoundFlatButton:
        text: 'MDRoundFlatButton'
        pos_hint: {'center_x': 0.5, 'center_y': 0.5}

    MDRoundFlatIconButton:
        icon: 'language-python'
        text: 'MDRoundFlatIconButton'
        pos_hint: {'center_x': 0.5, 'center_y': 0.4}

    MDFillRoundFlatIconButton:
        icon: 'language-python'
        text: 'MDFillRoundFlatIconButton'
        pos_hint: {'center_x': 0.5, 'center_y': 0.3}

    MDFillRoundFlatButton:
        text: 'MDFillRoundButton'
        pos_hint: {'center_x': 0.5, 'center_y': 0.2}

    MDTextButton:
        text: 'MDTextButton'
        pos_hint: {'center_x': 0.3, 'center_y': 0.1}

    MDIconButton:
        icon: 'language-python'
        pos_hint: {'center_x': 0.7, 'center_y': 0.1}

    MDFloatingActionButtonSpeedDial:
        data: app.data
        rotation_root_button: True

【问题讨论】:

  • 确保 main.kvmain.py 位于同一路径中。

标签: python pycharm kivy kivymd


【解决方案1】:

您可以直接指定您的 kv 文件所在的位置。

from kivy.lang.builder import Builder
from kivymd.app import MDApp


class MainApp(MDApp):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.data = {
            'Python': 'language-python',
            'PHP': 'language-php',
            'C++': 'language-cpp',
        }

    def build(self):
        return Builder.load_file('main.kv')


if __name__ == '__main__':
    app = MainApp()
    app.run()

【讨论】:

    【解决方案2】:

    如果您在 Ubuntu 中使用 PyCharm 并在其中安装了 kivymd,那么看到 kivymd 的白屏(blank black screen for kivy)是正常的。不正常的是,当您运行您的应用程序时,您的 .kv 文件代码没有显示在空白屏幕中。

    在 PyCharm for Ubuntu 中有一个奇怪的错误,你必须

    以全部小写命名您的 .kv 文件。

    否则,kivy 文件(.kv 文件)将无法识别或根本无法工作。

    例如。 “main.kv”而不是“Main.kv”

    希望能帮助到你。这很奇怪,我只在处理 kivy 或 kivymd 时使用 Ubuntu 中安装的 PyCharm 体验过它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多