I can't call ids when I declare it on main.py

23 views
Skip to first unread message

Victor Leal

unread,
Apr 1, 2019, 3:24:58 PM4/1/19
to Kivy users support
I am having problems when working with a TextInput in a function and need to call its value in another function.

I need to use the tInput.text and cInput.text values on add_Widget_popup function but i can't

Error: 
File "main.py", line 246, in add_Widget_popup
     tAux = self.ids.tAux.text
   File "kivy\properties.pyx", line 841, in kivy.properties.ObservableDict.__getattr__
 AttributeError: 'super' object has no attribute '__getattr__'

main.py
class Tarefas(Screen):
tarefas = []
cmds = []

def add_Widget_popup(self, *args):
tAux = self.ids.tAux.text
cAux = self.ids.cAux.text
if(tAux != ''):
pass
else:
tAux = '[color=ff3333]Sem descrição[/color]'
if(cAux != ''):
pass
else:
cAux = '[color=ff3333]##[/color]'

self.ids.box.add_widget(Tarefa(text = tAux, pText=cAux))
self.tarefas.append(tAux)
self.cmds.append(cAux)
self.saveData()

def addWidget(self, *args):

box2 = BoxLayout(orientation='vertical', padding=10, spacing=10)
Inputs = BoxLayout(padding=5, spacing = 10, orientation = 'vertical')
pop2 = Popup(title='Adicionar Comando', content=box2, size_hint=(None, None), size=(100, 30))

tlInput = Label(text = 'Descrição:', size_hint_y = None, height = 20)
tInput = TextInput(id='tAux', multiline = False, size_hint_y = None, height = 30)
clInput = Label(text = 'Comando:', size_hint_y = None, height = 20)
cInput = TextInput(id='cAux', multiline = False, size_hint_y = None, height = 30)
confirm = Botao(text = 'Confirmar', on_press=self.add_Widget_popup, on_release=pop2.dismiss)

Inputs.add_widget(tlInput)
Inputs.add_widget(tInput)
Inputs.add_widget(clInput)
Inputs.add_widget(cInput)
Inputs.add_widget(confirm)

box2.add_widget(Inputs)
anim = Animation(size=(500, 250), duration=0.05, t='out_back')
anim.start(pop2)
pop2.open()

 

Alexander Taylor

unread,
Apr 1, 2019, 5:34:06 PM4/1/19
to Kivy users support
ids are kv only, they don't do anything in Python, in fact the property is pointless and should probably be removed.

You can add things to the ids dict manually if you want, or pass references around some other way.

Victor Leal

unread,
Apr 1, 2019, 10:09:18 PM4/1/19
to Kivy users support
I tried, but i'm a beginner in python and kivy,  I could not reference otherwise.

Albert Saiz

unread,
Apr 2, 2019, 5:07:22 PM4/2/19
to Kivy users support
I usually use python to edit attributes of widgets from it's ID, it is possible. 
If what you're trying to do is to change the text of a widget, in your kv define it like that:

Label:
    id: whatever
    text: ""                         #you can put any default text here

And then from python, when you want it to change do:

self.ids.whatever.text = "new text"

I think the error in your code is trying to use the add_Widget like that.
Use self.ids.<id>.<attribute> just in attributes that already exist

Will Tejeda

unread,
Apr 2, 2019, 5:23:48 PM4/2/19
to kivy-...@googlegroups.com
I wonder if it's just an issue of calling it before it's created?
TAux text doesn't exist yet, right ?

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/fd6b6104-6a26-46bb-9321-d35cc8074acb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages