I was wrong i got to do one more update: The Accepted Answer now includes one way to reference generated Textinput by add_widget, so my Link is still an alternative but by editing the Answer theres a Solution much for all those of you who would like to stick with weakref and maybe its a nice way to start using weakref.
This is the last Edit of my Question: The Reason i was asking this question was my approach to get TextInput from automatic generated TextInput Widgets and add these text Inputs to a list.
My Approach was completely wrong, and this is the reason i got stuck. As i found a ton of other people asking for the same reason ( getting Textinput from user interface available for py logic) going for the same approach, getting stuck i do link a "Solution" which worked for me and enabled me to access TextInput without Widget Id:
I do really hope to save you guys some time. Anyway i marked the Answer as right because it given the solution for what i did ask for ( my Bad ).
I am really struggling to reference TextInput Widgets after generate them by User Input. I was trying walk() options already.
self.ids.grid.clear_widgets([i for i in self.ids.grid.children])
label1 = Label(text="Periode")
label2 = Label(text="Gross Income d Geschäftsfeldes")
self.ids.grid.add_widget(label1)
self.ids.grid.add_widget(label2)
for i in range(int(ButtonsZähler[0])):
label = Label(text="GI in Periode: -" + str(i+1))
text = TextInput(text=' ')
self.ids.grid.add_widget(label)
btn1 = Button(text="Close", )
self.ids.grid.add_widget(text)
self.ids['text'] = weakref.ref(text)
and i have the following kivy code related to this:
: name: 'RisikokapitalOperativesRisikoIII'
GridLayout:
id: Peter
cols: 1
GridLayout:
id: grid
name : grid
cols: 2
GridLayout:
id: grid2
cols: 2
Button:
id:zurruck
text:"Abbrechen"
on_press:
app.root.total_button = 5
on_release:
root.redo()
app.root.current = "RisikokapitalOperativesRisikoI"
root.manager.transition.direction = "left"
i dont know how to reference the text Input. Labels and Text Input are shown correctly. I want to add all text Inputs by User to one List. I have no clue how to work aroound the fact add_widget ist not abled to generate id in my kv File ?
kind regards
UPDATE: By Using the already given Help i could retrive the following information (a part of a list its given all widgets but i just post one ) in my console:
<weakref at 0x000001E761011D60; to 'TextInput' at 0x000001E760FFC7B0>
Wurst [<kivy.uix.textinput.TextInput object at 0x000001E760FFC7B0>,
I would like to be abled to acces the TextInput given by User and add this input to a list. As the Documentation is written for experienced users which i am not maybe someone is willing to give a easy to understandable Example ?
Your code:
self.ids['text'] = weakref.ref(text)
is adding the TextInput
to the ids
, but it is setting the key for all of them to the same value (text
). So, if you try to access the TextInput
using self.ids.text
you will only get the last TextInput
added. You can work around this problem by making unique keys for each TextInput
, maybe like:
self.ids[str(i+1)] = weakref.ref(text)
or just keep you own list of the TextInput
widgets:
self.ti_list = []
.
.
.
for i in range(int(ButtonsZähler[0])):
.
.
.
self.ti_list.append(text)
When looking at your code that creates the TextInputs
, the only thing that differentiates the TextInputs
is the value of i
. Everything else is the same. So that is used to record the TextInputs
. In the case of using ids
, you would access a TextInput
contents by its vale of i
as self.ids[str(i+1)].text
. Similarly, if you use a list, you can access the same as self.ti_list[i].text
.