[英]When running Python + Kivy program including multiprocessing, white blank screen appears
[英]Blank white screen when running kivyMD app. No compiler errors
所以我是 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
您可以直接指定您的 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()
对于 Ubuntu,PyCharm 中存在这个奇怪的错误,您必须
将 your.kv 文件命名为全部小写..(例如“main.kv”而不是“Main.kv”)
要不然!
您的 kivy 文件(.kv 文件)根本无法被 PyCharm 识别。
这很奇怪。 而且我只在 PyCharm 安装在 Ubuntu 和使用 Kivy 或 KivyMD 时体验过它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.