In my program I have a button that adds a new box. When you press a button in this new box it adds a new box, and so on. In each box I have a label, and I want to be able to change this text from the same textinput field. But I dont want the same text in each box, so I want to select the box, write the text, and then press a button so that the text is passed from the input field to that specific box/label. I have removed everything else from my app, so I will show you a complete code so you can try the program to understand what I mean.
I have tried to use a button on the main widget, but then I dont know how to choose which box that should be updated. I have also tried to use a button in the box (called "R" in the code), but then I only gets an error.
If i use the code that is commented out i get this error:
"AttributeError: 'super' object has no attribute '__getattr__'"
I would really appreciate some help! Thanks a lot.
This is the python file:
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
class Home(FloatLayout):
def first(self, *args):
a = box()
self.ids.frame.add_widget(a)
b = a.ids.btn3
b.bind(on_press=self.second)
c = a.ids.btn1
c.bind(on_press=self.textedit)
def second(self, *args):
d = box()
e = d.ids.mains
e.pos_hint={"right": .5, "top": .7}
self.ids.frame.add_widget(d)
f = d.ids.btn3
f.bind(on_press=self.third)
g = d.ids.btn1
g.bind(on_press=self.textedit)
def third(self, *args):
h = box()
i = h.ids.mains
i.pos_hint = {"right": .3, "top": .9}
self.ids.frame.add_widget(h)
j = h.ids.btn1
j.bind(on_press=self.textedit)
def textedit(self, *args):
print("Hello")
#k = self.ids.tinput.text
#l = self.ids.lab
#l.text = k
def textedit2(self, *args):
print("hei")
#This is the submitbutton on the main widget
class HiApp(App):
def build(self):
return Home()
class box(FloatLayout):
pass
if __name__ == "__main__":
HiApp().run()
This is the .kv file
<Home>:
FloatLayout:
id: frame
size_hint_y: 1
pos_hint:{"right":1,"top":1}
canvas.before:
Color:
rgba: (1, 1, 1, 1)
Rectangle:
size: self.size
pos: self.pos
BoxLayout:
id: boks
orientation: "vertical"
size_hint_x: .20
size_hint_y: .15
pos_hint:{"right":1,"top":1}
canvas.before:
Color:
rgba: (0, 1, 0, 1)
Rectangle:
size: self.size
pos: self.pos
TextInput:
id: tinput
hint_text: "Frome here"
Button:
id: t_sub
text: "Submit"
on_press: root.textedit2()
Button:
id: start
text: "Start"
font_size: 20
color: 0, 0, 0, 1
background_normal: ''
background_color: .88, .88, .88, 1
size_hint: .1, .1
pos_hint:{"right":.5,"top":.35}
on_press: root.first()
<box>:
BoxLayout:
id: mains
orientation: "vertical"
size_hint_x: .18
size_hint_y: .13
pos_hint:{"right":.3,"top":.5}
canvas.before:
Color:
rgba: (.20, .05, .0, 1)
Rectangle:
size: self.size
pos: self.pos
BoxLayout:
id: c1
size_hint_y: .25
pos_hint:{"left":.1,"top":.5}
GridLayout:
rows: 1
cols: 3
padding: 4
spacing: 4
Button:
id: btn1
text: "R"
font_size: 30
color: 0, 0, 0, 1
background_normal: ''
background_color: .88, .88, .88, 1
size_hint: .3, .3
pos_hint:{"left":.5,"top":.5}
on_press:
Button:
id: btn2
text: "-"
font_size: 30
color: 1, 0, 0, 1
background_normal: ''
background_color: .88, .88, .88, 1
size_hint: .3, .3
pos_hint:{"left":.5,"top":.5}
on_press:
Button:
id: btn3
text: "+"
font_size: 30
color: 0, 1, 0, 1
background_normal: ''
background_color: .88, .88, .88, 1
size_hint: .3, .3
pos_hint:{"left":.5,"top":.5}
on_press:
GridLayout:
rows: 1
cols: 2
padding: 4
spacing: 4
Label:
id: lab
text: "Text here"
TextInput:
hint_text: "0"