Python Forum

Full Version: How to clear a TextInput field
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,
I need to clear a TextInput field

This is my Python code
b2=(Button(text='Clear'))
self.add_widget(b2)
b2.bind(on_press=self.clsInputText)

def clsInputText(self):
   self.username=""
I receive this error message

TypeError: clsInputText() takes exactly 1 argument (2 given)

Any help will be greatly appreciated.
Thanks in advance for your kind support.
Regards,
Giovanni
which GUI package?
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.boxlayout import BoxLayout


class DemoApp(App):
    def build(self):
        self.box = BoxLayout(orientation='vertical', spacing=10)
        self.txt = TextInput()
        self.btn = Button(text='Clear', on_press=self.clear_txt)
        self.box.add_widget(self.txt)
        self.box.add_widget(self.btn)
        return self.box
        
    def clear_txt(self, instance):
        self.txt.text = ''


if __name__ == '__main__':
    DemoApp().run()