首先,这是一段很大的代码,所以为了这个问题,我会尽量简化它。我有一个Kivy语言脚本,它有一个根小部件,有一个操作栏和boxlayout。代码的一般结构有点像这样(我认为回答这个问题不需要这样,但这里无论如何都是这样):Root > MenuBarWidg > BoxLayout > Image + Other buttons/labels...
。你知道吗
现在,这里是我的小部件在kivy中的样子(对于boxlayout):
<DisplayPhoto>:
Image:
id: image_display
allow_strech: True
#StringProperty in the class
source: root.image_path
Button:
在我的python脚本中:
class DisplayPhoto(BoxLayout):
image_path = StringProperty()
def __init__(self, **kwargs):
super(DisplayPhoto, self).__init__(self)
self.image_path = 'reload.png'
#this is called from another class on a button press
def update(self):
self.image_path = 'new_image_path.png'
在python脚本中调用update时,什么都不会发生。我试过print(self.image_path)
,它显示new_image_path.png
,但它也是一个字符串,而不是kivy对象。你知道吗
我曾经尝试过一些事情,比如通过调用id
来更新source
等等,但是没有成功。感谢您的帮助!你知道吗
我想问题在于如何调用
update()
方法。你知道吗请参考以下代码
一种方法是:
你知道吗主.py你知道吗
你知道吗主电源.kv地址:
另一种方法是使用事件调度器
你知道吗主.py地址:
你知道吗主电源.kv你知道吗
相关问题 更多 >
编程相关推荐