from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
class MyApp(App):
def build(self):
self.window = GridLayout(cols=1)
self.window.add_widget(Image(source="logo.png"))
self.greeting = Label(text="Hello", font_size=18)
self.window.add_widget(self.greeting)
MyApp().run()
终端识别出图像和标签已导入,但不会在窗口中显示它们。
我期待弹出一个窗口,显示我上传的图像和标签。
build() 方法需要返回根部件,在本例中为 self.window。
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.image import Image
class MyApp(App):
def build(self):
self.window = GridLayout(cols=1)
self.window.add_widget(Image(source="logo.png"))
self.greeting = Label(text="Hello", font_size=18)
self.window.add_widget(self.greeting)
return self.window
MyApp().run()