TextInput stopped working suddenly

18 views
Skip to first unread message

Shoumik Das

unread,
May 3, 2020, 1:20:05 AM5/3/20
to Kivy users support
Hi, I am building a simple Kivy app with a couple of screens. The first screen has a couple of buttons which, when clicked, move to the second screen. The second screen has a text input widget and a button inside a Float Layout. The layout is loaded as a root widget by an explicit call to the kv file through Builder.

Everything was working fine and I added a 'focus: True' tag in the text input attributes. The app worked fine and I could type in the text input field with focus set as True. However, the text input field suddenly stopped working without any change in code or layout. I was not sure and searched Google for a couple of probable solutions, none of which worked:

1. Removed the 'focus: True' attribute and reloaded the app but the text input field still did not respond. I was unable to type anything from my keyboard.

2. Another post pointed out that the kv file was being loaded twice resulting in erratic behaviour. I tried to remove the explicit Builder file call and returned the root widget (Screen Manager) in the main code. However, it messed up my entire app and only showed a black empty screen.

Can you please advise as to what I may be doing wrong? The code is provided below:

Python Code:

from kivy.config import Config
# Config.set should be used before importing any other Kivy module.
Config.set('kivy','window_icon','sivaicon.png')
# Config set for resizing image button
Config.set('graphics', 'resizable', True)
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.button import Button
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.image import Image
# from kivy.graphics.context_instructions import Color
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.lang.builder import Builder


class SivaLoginScreen(Screen):
# Canvas initiation at instance level. Not necessary if the canvas is defined in the kv file.
#    def __init__(self,**kwargs):
#        super(SivaLoginScreen,self).__init__(**kwargs)
#        with self.canvas.before:
#            Color(253,253,152,1)
    def twitter_authentication(self):
        App.get_running_app().root.current='verify_screen'

    def linkedin_authentication(self):
        App.get_running_app().root.current='verify_screen'


class SivaVerifyScreen(Screen):
    pass


class SivaTabbedScreen(Screen):
    pass


class SivaScreenManager(ScreenManager):
    pass


class ImageButton(ButtonBehavior, Image):
    pass


# Tell Kivy to directly load a file. If this file defines a root widget, it will be returned by the method.
root_widget = Builder.load_file('siva.kv')

class SivaApp(App):
    def build(self):
        # Initialize root widget
        return root_widget


if __name__ == '__main__':
    # Run application
    SivaApp().run()

kv file:

SivaScreenManager:
    SivaLoginScreen:
    SivaVerifyScreen:
    SivaTabbedScreen:


<ImageButton>:
    keep_ratio: True


<SivaLoginScreen>:
    name: 'login_screen'
    canvas.before:
        Color:
            rgba: 195/255, 60/255, 35/255, 1
        Rectangle:
            pos: self.pos
            size: self.size
    FloatLayout:
        size: root.width, root.height
        Image:
            id: login_logo_siva
            source: 'images/sivalogo1.png'
            keep_ratio: True
            size_hint: 0.3, 0.3
            pos_hint: {'center_x':0.5, 'center_y':0.75}
        Label:
            id: login_label_siva
            pos: self.x*0.5-4, self.y*0.5+15
            markup: True
            font_name: 'roboto/Roboto-Medium.ttf'
            text: '[color=#FDFD98]S.[/color][color=#B29DD9]I[/color][color=#FDFD98].[/color][color=#77DD77]V[/color][color=#FDFD98].[/color][color=#779ECB]A[/color]'
            font_size: '40sp'
        Label:
            id: login_label_slogan1
            pos: self.x*0.5-3, self.y*0.5-6
            markup: True
            font_name: 'roboto/Roboto-Regular.ttf'
            text: '[color=#FDFD98]SLOGAN TEXT[/color]'
            font_size: '13sp'
        Label:
            id: login_label_slogan2
            pos: self.x*0.5-3, self.y*0.5-20
            markup: True
            font_name: 'roboto/Roboto-Regular.ttf'
            text: '[color=#FDFD98]HEADLINE TEXT[/color]'
            font_size: '13sp'
        BoxLayout:
            id:login_button_layout
            orientation: 'horizontal'
            size_hint: 0.2, 0.2
            pos_hint: {'center_x':0.5, 'center_y':0.25}
            ImageButton:
                id: twitter_button
                source: {'normal': 'images/twitter-96.png', 'down': 'images/twitter-96.png'} [self.state]
                on_release: root.twitter_authentication()
            ImageButton:
                id: linkedin_button
                source: {'normal': 'images/linkedin-96.png', 'down': 'images/linkedin-96.png'} [self.state]
                on_release: root.linkedin_authentication()


<SivaVerifyScreen>:
    name: 'verify_screen'
    canvas.before:
        Color:
            rgba: 195/255, 60/255, 35/255, 1
        Rectangle:
            pos: self.pos
            size: self.size
    FloatLayout:
        size: root.width, root.height
        Label:
            id: verify_label
            markup: True
            font_name: 'roboto/Roboto-Regular.ttf'
            text: 'Paste the verification code'
            font_size: '16sp'
            pos_hint: {'center_x':0.5, 'center_y':0.7}
            size_hint: 1, 0.4
        TextInput:
            id: verify_input
            multiline: False
            font_size: '30sp'
            pos_hint: {'center_x':0.5, 'center_y':0.55}
            size_hint: 0.5, 0.1
        ImageButton:
            id: verify_button
            source: {'normal': 'images/lock-96.png', 'down': 'images/lock-96.png'} [self.state]
            pos_hint: {'center_x':0.5, 'center_y':0.35}
            size_hint: 0.5, 0.5


<SivaTabbedScreen>:
    name: 'tabbed_screen'
    FloatLayout:
        size: root.width, root.height
        Label:
            pos: self.x*0.5, self.y*0.5
            text: 'SECOND SCREEN'
            font_size: '50sp'

Please advise. I am helplessly stuck. :(

Thanks in advance

Elliot Garbus

unread,
May 3, 2020, 8:54:33 AM5/3/20
to kivy-...@googlegroups.com

For these kinds of problems the easiest way to get to root cause is to run the inspector tool.  This is an amazing tool that lets you exampine the widgets in your app – some attributes you can even change right in the tool.

 

Run:  python siva.py -m inspector

Press control-e to bring up the inspector.  Click on the widgets.

 

More info: https://kivy.org/doc/stable/api-kivy.modules.inspector.html#module-kivy.modules.inspector

 

You will see you have widgets overlapping the TextInput.  I suggest using a BoxLayout, rather than a FloatLayout to hold the lable, textinput and button in the siva verify screen.

--
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/fc3aa2fb-1d37-4ab0-b678-619060975fbb%40googlegroups.com.

 

Shoumik Das

unread,
May 3, 2020, 9:03:51 AM5/3/20
to Kivy users support
Hi Eliott,

Thank you very much for the advice. You are a life-saver!! Yes, indeed my button widget was over lapping the TextInput widget above it. Reducing the size_hint made it work for me. I also changed the way I return the root widget so that the kv file is not loaded twice. It is now working fine.

On a different note, I initially did try with a box layout in the vertical orientation. The text label, input box and button were stacked vertically. What I noticed was that the button image was appearing too close to the text input field and was even overlapping it in case the screen size the reduced. Hence, I switched to a Float Layout.

Is there a way to introduce some kind of padding between the various widgets inside a Box Layout?

Thanks a ton!

To unsubscribe from this group and stop receiving emails from it, send an email to kivy-...@googlegroups.com.

Elliot Garbus

unread,
May 3, 2020, 9:08:00 AM5/3/20
to kivy-...@googlegroups.com

There are 2 attributes padding and spacing.  Padding adds space between the layout and the widgets, like a frame between the layout and the widgets.  Spacing puts space between the widgets. For this example use spacing.

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/f31fc5d2-2bb4-41d4-bcde-627fee16e3b7%40googlegroups.com.

 

Shoumik Das

unread,
May 3, 2020, 9:09:55 AM5/3/20
to Kivy users support
Just one word for you. Amazing!

Elliot Garbus

unread,
May 3, 2020, 9:10:46 AM5/3/20
to kivy-...@googlegroups.com

😊

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/828f2ee7-12f6-4dd0-ac6f-0c15407b3287%40googlegroups.com.

 

Reply all
Reply to author
Forward
0 new messages