'making textinput widget on the basis of items in list in a popup and reading the text in in it using kivy framework-
def get_credential_fields_for_popup_success(self, urlrequest, data):
# print(data)
# print(data['fields'])
s = list(data['fields'].values())
# print(s)
r = list(s[0].values())
# print(r)
c = list(r[0].values())
# print(c)
list_of_widget = []
for i in c[0]:
s = list(i.values())
list_of_widget.append(s)
real_list = []
for i in list_of_widget:
# print(i[0])
real_list.append(i[0])
self.widgets = real_list
# print(real_list)
def OpenPopupWindow(self):
self.layout = GridLayout(rows=len(self.widgets) + 1)
#count = 0
for i in range(0, len(self.widgets)):
self.arr = ['zero', 'one', 'two', 'three', 'four']
name = self.arr[i]
name= ObjectProperty(None)
print(name)
if i == 0 :
self.label = MDLabel(text = self.widgets[i])
self.name = TextInput(text="", multiline=False, hint_text=self.widgets[i])
#print(self.widget_name.text)
else :
self.label = MDLabel(text= self.widgets[i])
self.name = TextInput(text="", multiline=False, hint_text=self.widgets[i],password= True)
#print(self.widget_name.text)
self.layout.add_widget(self.label)
self.layout.add_widget(self.name)
#print(self.ids.layout)
#for i in range(0, len(self.widgets)):
# layout.add_widget()
self.button = Button(text="Close", size_hint=(0.2, 0.2), pos_hint={'center_x': 0.2, 'center_y': 0.2})
self.button.bind(on_press= self.cred_save)
self.layout.add_widget(self.button)
self.popup = Popup(title="test Popup", content=self.layout, size_hint=(None, None), size=(300, 400),
background="atlas://images/my_popup/white (2) (1)",
auto_dismiss=True)
self.popup.open()
#print(self.ids.1.text)
#print(self.ids.2.text)
def cred_save(self,obj):
#print('name'+self.ids.layout.ids.zero.text)
#print('name'+self.layout.one.text)
#print('name'+se lf.layout.two.text)
user_id = self.zero.text
password = self.one.text
pin = self.two.text
print(user_id)
print(password)
#self.popup.dismiss()
#print(self.ids.)
#self.popup.dismiss()
client_id = self.zero.text
Here , I am getting a list whose length will determine the textinput field in the popup on trigerring the OpenPopupWindow, in this function i made a popup. Inside it , made gridlayout nd binded input fields , and i have tried everything to get the text written in input fileds after pressing the button but i am not able to get the text written in other function which i have called on_press the button widget in popup.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|