简体   繁体   English

在按钮按下 kivy 时刷新小部件

[英]Refresh a widget on button press kivy

I have a kivy widget thats value updates during runtime which also change the number of labels and buttons in it since I build it in a for loop in python.我有一个 kivy 小部件,它在运行时更新值,它也改变了其中的标签和按钮的数量,因为我在 python 的 for 循环中构建了它。

I call a method inside the init class to get the data needed to build it at start.我在init类中调用一个方法来获取在开始时构建它所需的数据。 However I want to update that Screen with the press of a button, basically refresh the widget since if the app was to boot up again the page would be different.但是我想通过按下按钮来更新该屏幕,基本上刷新小部件,因为如果应用程序再次启动,页面会有所不同。

I tried:我试过了:

self.but1.bind(on_press = lambda x:  self.parent.parent.parent.parent.parent.submit_all.rev.canvas.ask_update())

I thought this could maybe refresh my widget however this has no affect, even tho I recieve no error.我认为这可能会刷新我的小部件,但这没有影响,即使我没有收到错误。

-The class I need to refresh is called ReviewLayout with the id 'rev' - 我需要刷新的类称为 ReviewLayout,ID 为“rev”

TLDR; TLDR; I want a to assign a method to the a button(on_press) that rebuilds the widget like the app was freshly launched.我想为一个按钮(on_press)分配一个方法来重建小部件,就像应用程序刚刚启动一样。

我通过将我通常放入init方法中的内容全部放入另一个方法中并调用该方法 on_press 解决了这个问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM