Python Forum
[Kivy] How to clear a TextInput field
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Kivy] How to clear a TextInput field
#1
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
Reply
#2
which GUI package?
Reply
#3
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to read text in kivy textinput or Label jadel440 1 5,223 Dec-29-2020, 10:47 AM
Last Post: joe_momma
  [Turtle] numinput and textinput do not work fgarciamoran 1 3,151 Apr-28-2020, 08:44 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020