Click here to Skip to main content
15,568,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
A simplified version of my problem is:

<ValueInput>:
     TextInput:
         id: value_input
         on_text_validate: root.value_input(value_input.text)

<DefineVariables>:
     Button:
        on_press: root.clear_text()


I have two different classes ValueInput and DefineVariables. What I want to happen is that when I press the Button from <definevariables>, the text of which the user has written in TextInput from <valueinput> shall be cleared.

In the .py file:
class MainWidget(BoxLayout):

    ValueInput = NumericProperty(0)


class ValueInput(MainWidget):

    def value_input(self, ValueInput):
        ValueInput = ValueInput
        self.ids.value_input.text = ""  #This clears the TextInput box.


class DefineVariables(MainWidget):

    def clear_text(self):
        CLEAR HERE


If I go to the .py file I figured out that if i do
self.ids.value_input.text

in the ValueInput class, it does clear the text when pressing enter. BUT, I dont want the
self.ids.value_input.text
function to be in that class. I want to do
self.ids.value_input.text
when I press the button of which I have decleared in the Kivy file.

What happens if I do
def clear_text(self):
    self.ids.value_input.text = ""


and call the clear_text function using root.clear_text() in the .kv file is that i get this error:
AttributeError: 'super' object has no attribute '__getattr__'

How could I make this work?

What I have tried:

Using a clear_text function in the DefineVariables but to no success.
Posted
Updated 2-Nov-21 3:42am
Comments
Richard MacCutchan 2-Nov-21 8:12am    
You need to call the clear_text method on an instance of the ValueInput class. But I cannot see from your code exactly what is happening, or what produces that error.
Daniel Lidén 2-Nov-21 8:43am    
Sorry I do not see what you mean.
Here is the exact code producing the error.
main.py file:
from kivy.app import App
from kivy.properties import NumericProperty
from kivy.uix.boxlayout import BoxLayout


class MainWidget(BoxLayout):

    ValueInput = NumericProperty(0)


class ValueInput(MainWidget):

    def value_input(self, ValueInput):
        Value = ValueInput
        print(Value)


class DefineVariables(MainWidget):

    def clear_text(self):
        self.ids.value_input.text = ""


class CalcApp(App):
    pass


CalcApp().run()


calc.kv file:
MainWidget:
    ValueInput:
    DefineVariables:


<ValueInput>:
    TextInput:
        id: variable_input
        multiline: False
        on_text_validate: root.value_input(variable_input.text)

<DefineVariables>:
    Button:
        text: "Clear"
        on_press: root.clear_text()



I run the application. A TextInput next to a Button appears. I write something in the TextInput and press enter. Then when I press "Clear" button its supposed to remove what I have written in the TextInput box but instead I get
 AttributeError: 'super' object has no attribute '__getattr__'


Could you change the code so I can see what I need to do. First time ever using Kivy.
Richard MacCutchan 2-Nov-21 9:03am    
Sorry, I cannot see what the error message means. You need to check the KIVY (whatever that is) documentation to see that your class designs are correct.

Most likely a better place for assistance would be the kivy help forum.
Daniel Lidén 2-Nov-21 9:12am    
Ok! Thanks anyways!
Richard MacCutchan 2-Nov-21 9:48am    
Try this:
    def clear_text(self):
        self.ids['value_input'] = ""

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900