disable button when TextInput is empty

14 views
Skip to first unread message

Glen Rubin

unread,
Jan 21, 2023, 12:55:04 PM1/21/23
to Kivy users support
I want to enable/disable a button depending on whether there is text present in a TextInput


I tried something like: 
TextInput:
    id: login
Button:
    disabled: not login.text

but then i get the error:

 AttributeError: module 'login' has no attribute 'text'

I guess b/c there is no text the attribute doesn't exist yet?  maybe i need to do this from python?



Elliot Garbus

unread,
Jan 21, 2023, 5:58:59 PM1/21/23
to kivy-...@googlegroups.com

Perhaps the attribute is not created at the time of the test.  Initialization order can be confusing.

 

Share an executable example that shows the problem.

 

I put together a small example – but it works as expected.

 

from kivy.app import App
from kivy.lang import Builder

kv =
"""
BoxLayout:
    orientation: 'vertical'
    AnchorLayout:
        TextInput:
            id: login
            size_hint: None, None
            size: 400, 30
    Button:
        text: 'Text Box Controlled'
        size_hint_y: None
        height: dp(48)
        disabled: not login.text
"""


class TextButtonApp(App):
   
def build(self):
       
return Builder.load_string(kv)

TextButtonApp().run()

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/d33befde-8d0e-4a77-8849-130c1c3ed7c0n%40googlegroups.com.

 

Glen Rubin

unread,
Jan 22, 2023, 10:37:30 AM1/22/23
to kivy-...@googlegroups.com
i figured out what was going on here.  at the top of my kv file i import the python file login as login and so that name at load conflicted with the login id assigned to the textinput.  I changed the login id and it works fine just like your example!  thanks again!

You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/36_UQ5D4Wxs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/63cc6e2c.170a0220.84959.6e78SMTPIN_ADDED_MISSING%40gmr-mx.google.com.

Elliot Garbus

unread,
Jan 22, 2023, 11:25:59 AM1/22/23
to kivy-...@googlegroups.com
👍

Sent from my iPhone

On Jan 22, 2023, at 8:37 AM, Glen Rubin <rubi...@gmail.com> wrote:


Reply all
Reply to author
Forward
0 new messages