Click here to Skip to main content
15,881,757 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 29-May-23 1:12am
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'] = ""

1 solution

Kv
<ValueInput>:
value_input:value_input
TextInput:
id: value_input
pos: 100, 100

<DefineVariables>:
Button:
on_press: root.clear()
on_release: root.fill()

MainWidget:
<MainWidget>:

ValueInput:
DefineVariables:

Python code


class ValueInput(Widget):

text = 'p'

def __init__(**kwargs)
super ().__init__(**kwargs)
Clock.schedule_interval (self.clear2, 1/60)

def clear1(self):
Valueinput.text = ""

def clear2(self):

if self.text == "":
self.value_input.text = self.text

else:
pass



class DefineVariables(MainWidget):

def clear(self):
ValueInput.clear1(self)

def fill(self):
ValueInput.text = 'p'

class MainWidget(widget):
pass


I write this by mobile so take care of common mistakes
And it's working like you want
 
Share this answer
 
v5
Comments
Richard Deeming 30-May-23 4:42am    
"I know the answer, but I'm not telling you unless you reply" is clearly not a solution to this question.

And quite frankly, it stinks of a scam.
Muhammad ali Mansoor 30-May-23 8:30am    
Here's your solution
Dave Kreskowiak 30-May-23 8:53am    
Considering this is TWO YEARS later, I don't think the OP is still looking for an answer.
Muhammad ali Mansoor 30-May-23 9:04am    
Yeah I know for that I say first that if anybody wants answer then reply and someone reply me that you're a scammer
Dave Kreskowiak 30-May-23 9:37am    
Yeah, and I agree with him. Just posting that message screams, "I'm a scammer trying to get your email address so I can send you tons of spam!"

Next time, look at the date on the question. If it's years later, chances are really good you're not going to get a reply.

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