我想制作一个带有包含图像的小部件的小程序,当你点击它时会更改图像,但是当我运行程序时它没有显示小部件。 相反,它显示了一个空的屏幕,但带有correckt backgroundcolor。
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import StringProperty
kv_string = Builder.load_string('''
<Root>:
Feld:
pos_hint: {"right": 1, 'top': 1}
id: a1
<Feld>:
Image:
pos: root.pos
id: my_image
source: root.weg
''')
class Root(FloatLayout):
kr = StringProperty('kreuz.png')
ks = StringProperty('kreis.png')
def __init__(self, *args, **kwargs):
super(Root, self).__init__(*args, **kwargs)
Clock.schedule_interval(self.Update, 1/60.)
def Update(self, *args):
pass
class Feld(Widget):
weg = StringProperty('hinterg.png')
def __init__(self, *args, **kwargs):
super(Feld, self).__init__(*args, **kwargs)
Clock.schedule_interval(self.Update, 1/60.)
def Update(self, *args):
pass
def on_touch_down(self, touch):
if self.ids.my_image.collide_point(*touch.pos):
self.weg = self.parent.kr
class TTT(App):
def build(self):
Window.clearcolor = (0, 1, 1, 1)
return kv_string
if __name__ == "__main__":
TTT().run()
答案 0 :(得分:1)
您的根小部件是kv_string,它是None,因为该变量是不包含根小部件的字符串上的Builder.load_string的结果。