如何访问kivy中嵌套小部件中的小部件ID



你好,我在kivy中的代码有问题。

当我在boxlt中添加Finance2(屏幕(时,我在textinput中放入了新值,但textinput的值不会更新。当我打印box2值时,它只有旧值。当我在屏幕1文本输入中更改值时,值不会在框2中分配。

我想知道我需要做什么才能通过screen1访问id box2以获得更新的值。

Screen 1
boxlayout
id:boxlt
self.ids.boxlt.add_widget(Finance2())
Finance2(screen)
Textinput
id: box2

小部件是考虑这个例子的对象。

在你的kivy文件中,你有这样的东西:

<first_screen>
ScrollView:    
size: root.width*0.12, root.height*0.7
pos: root.width*1.1, root.height*0.2
GridLayout:
id: scrolled_grid
height: self.minimum_height
size_hint_y: None
spacing: 10  
clos: 1

在你的主页上,你有这个:

class first_screen(Widget):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.list_of_btns = []
for i in range(4):            
self.obj_btn = Button(text= 'test '+str(i), font_size='0',size_hint_x=1, size_hint_y=None, pos=(0,self.height/i), on_press=self.test)
self.ids.scrolled_grid.add_widget(self.obj_btn)
### now there are 5 objectes appended to the scrolled_grid 
##  to keep track append them
#   to a list  self.list_of_btns
def test(self, instance):
print(instance.text)  ## output is 'test' + str(i) 
## if u want to delete any of them u just 

self.ids.scrolled_grid.remove(self.list_of_btns[0]) 
## this delets the first item u can loop to delete them all

只需记住将它们保存在列表中,以便稍后处理

最新更新