【发布时间】: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.kv与main.py位于同一路径中。
标签: python pycharm kivy kivymd