Hey guys, I have a question that should theoretically be simple, but I do not know how to do it. Basically I'm doing a simple app where you can create tasks and add to a list, I wanted to make a screen to show the tasks created and one to create the tasks (for now I only managed to do both on a screen), only then the problem arises, screens are classes, so when I'm going to call my method of creating the task on the specified screen, it gives error because this method of creating does not belong to that class.
How would I refer to this method from another class, if it is not possible which is the best solution?
class Tarefas(Screen):
def __init__(self,tarefas = [], **kwargs):
super().__init__(**kwargs)
for tarefa in tarefas:
self.ids.box1.add_widget(Tarefa(text=tarefa))
def addWidget(self):
texto = self.ids.texto.text
nome = self.ids.nameinput.text
self.ids.box1.add_widget(Tarefa(text = texto, name = nome))
self.ids.texto.text = ''
self.ids.nameinput.text = ''
class Tarefa(GridLayout):
def __init__(self, name, text='', **kwargs):
super().__init__(**kwargs)
self.ids.label1.text = text
self.ids.label2.text = name
KV file
<Tarefas>:
GridLayout:
canvas:
Color:
rgba:1,1,1,1
Rectangle:
size:self.size
pos:self.pos
rows:2
ScrollView:
BoxLayout:
orientation:'vertical'
id:box1
height:self.minimum_height
size_hint_y: None
BoxLayout:
Botao:
text:' Criar tarefa'
on_press: app.root.current = 'criar'
<Tarefa>:
canvas:
Color:
rgba:0.1,0.5,0.7,1
Rectangle:
size: self.size
pos: self.pos
rows:2
cols:3
size_hint_y:None
height:100
Label:
id:label2
font_size:20
Label:
id:label1
font_size:20
Botao:
text:'√¯'
font_size: 40
size_hint_x: None
size_hint_y: None
height:30
width: 30
on_press:app.root.get_screen('tarefas').ids.box1.remove_widget(root)
<Criar>:
BoxLayout:
orientation:'vertical'
Label:
text:'Tarefa'
size_hint: None, None
width:50
color: 0,0,0,1
height:60
TextInput:
id:nameinput
height:30
size_hint_y:None
height: 60
Label:
text:'Horário'
size_hint: None, None
width:50
color: 0,0,0,1
height:60
TextInput:
id:texto
height:30
size_hint_y: None
height:60
Botao:
text:'Criar'
on_press: root.addWidget()
The code should be messy, but I make it clear that I'm a beginner, I've pasted everything but the method is in the last line.
Thank you in advance.