下面的代码将产生一个空白屏幕,标题为“ Test”,仅此而已。没有错误讯息。请问我在做什么错了?
#!/usr/bin/env python3
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.scatter import Scatter
class MyScreen(Widget):
def __init__(self):
Widget.__init__(self)
f = FloatLayout()
s = Scatter()
l = Label(text="Hello, World!", font_size=100)
f.add_widget(s)
s.add_widget(l)
class TestApp(App):
def build(self):
return MyScreen()
if __name__ == "__main__":
TestApp().run()
答案 0 :(得分:0)
f = FloatLayout()
s = Scatter()
l = Label(text="Hello, World!", font_size=100)
f.add_widget(s)
s.add_widget(l)
这些将小部件添加到布局中-但是您没有将布局添加到主App类中
尝试
self.add_widget(f)