Change border color of an InputText

246 views
Skip to first unread message

Michael Magro

unread,
Feb 22, 2021, 11:27:01 AM2/22/21
to Kivy users support
Hello guys, how do I set a border in the red color of an InputText?

I would like to do this to simulate an inputtext validation..


My code:

TextInput:
      id: login
      multiline:False
      background_color: [1,1,1,1]
      hint_text: 'Seu e-mail'
      font_size: '12dp'
      size_hint: (1, None)
      height: '44dp'
      size_hint_x: 0.85
      pos_hint: {'center_x': .5}
      padding: [20, (self.height-self.line_height)/2]

Elliot Garbus

unread,
Feb 22, 2021, 4:34:37 PM2/22/21
to kivy-...@googlegroups.com

Use the canvas to draw a rectangle around the TextInput.  Change the color to red if the there is an issue with the content.

--
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/f827bcfe-c11f-422e-a376-006ddb992979n%40googlegroups.com.

 

Elliot Garbus

unread,
Feb 22, 2021, 4:55:52 PM2/22/21
to kivy-...@googlegroups.com

Here is an example:

 

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.textinput import TextInput
from kivy.properties import ColorProperty, ListProperty

kv =
"""
<OutlineTextInput>:
    canvas.after:
        Color:
            rgba: root.color
        Line:
            width: 2
            rectangle: (*self.pos, *self.size)
           
BoxLayout:
    orientation: 'vertical'
    Label:
        text: 'Change Textbox Outline Color'
    OutlineTextInput:
        id: oti
        size_hint_y: None
        height: 30
    BoxLayout:
        size_hint_y: None
        heignt: 48
        Button:
            text: 'outline color black'
            on_release: oti.color = 'black'
        Button:
            text: 'outline color red'
            on_release: oti.color = 'red'
"""


class OutlineTextInput(TextInput):
    color = ColorProperty(
'black')


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


ColorTIBorder().run()
Reply all
Reply to author
Forward
0 new messages