pycharm 运行kivyMD应用程序时出现白色,无编译器错误

bnlyeluc  于 2023-01-02  发布在  PyCharm
关注(0)|答案(2)|浏览(197)

所以我是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()

在主.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
gblwokeq

gblwokeq1#

您可以直接指定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()
rjee0c15

rjee0c152#

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

命名您的.kv文件时全部使用小写字母!!(例如“main.kv”而不是“Main.kv”)
否则!

你的kivy文件(.kv文件)将不会被PyCharm识别。
这很奇怪,我只有在Ubuntu中安装PyCharm时,以及在使用Kivy或KivyMD时,才经历过这种情况。

相关问题