Search code examples
pythonpycharmkivytextarea

Why doesn't TextInput appear in Kivy layout when launching from PyCharm?


I have the following minimal Kivy application. If I use Buttons (as below) I get an application with three buttons (see screenshot). If I change them to TextInput I get an empty black window. The application also appears to hang (the close button doesn't work, I have to kill the python process).

How can I add define a BoxLayout with three TextInput objects in the kv file?

example.py

from kivy.app import App
from kivy.uix.widget import Widget


class ExampleWidget(Widget):
    pass


class ExampleApp(App):
    # loads example.kv by convention

    def build(self):
        return ExampleWidget()


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

example.kv

#:kivy 2.1.0

<ExampleWidget>:
    BoxLayout:
        center: root.center
        height: root.height
        width: root.width
        TextInput:
            text: "First"
        TextInput:
            text: "Second"
        TextInput:
            text: "Third"

Screenshot

Empty Kivy window with no visible TextInputs

Screenshot (using Buttons)

If I literally replace TextInput with Buttons in example.kv the example works. Also notice that the window title "Example" is rendered.

Kivy application with three buttons in a BoxLayout

Output when launching application:

[INFO   ] [Logger      ] Record log in /home/user/.kivy/logs/kivy_22-06-22_99.txt
[INFO   ] [Kivy        ] v2.1.0
[INFO   ] [Kivy        ] Installed at "/home/user/.local/share/virtualenvs/application-6A38KkjJ/lib/python3.8/site-packages/kivy/__init__.py"
[INFO   ] [Python      ] v3.8.10 (default, Mar 15 2022, 12:22:08) 
[GCC 9.4.0]
[INFO   ] [Python      ] Interpreter at "/home/user/.local/share/virtualenvs/application-6A38KkjJ/bin/python"
[INFO   ] [Logger      ] Purge log fired. Processing...
[INFO   ] [Logger      ] Purge finished!
[INFO   ] [Factory     ] 189 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2 (img_pil, img_ffpyplayer ignored)
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] Backend used <sdl2>
[INFO   ] [GL          ] OpenGL version <b'4.6 (Compatibility Profile) Mesa 21.2.6'>
[INFO   ] [GL          ] OpenGL vendor <b'Intel'>
[INFO   ] [GL          ] OpenGL renderer <b'Mesa Intel(R) Iris(R) Plus Graphics (ICL GT2)'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 6
[INFO   ] [GL          ] Shading version <b'4.60'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event5
[INFO   ] [MTD         ] Read event from </dev/input/event5>
[INFO   ] [Base        ] Start application main loop
[INFO   ] [GL          ] NPOT texture support is available
[WARNING] [MTD         ] Unable to open device "/dev/input/event5". Please ensure you have the appropriate permissions.

Solution

  • This issue is triggered by the PyCharm launch configuration. When I launch the same code from the command line, the text input fields are rendered (roughly) as expected:

    cd example
    pipenv shell
    python example.py
    

    This is the equivalent of selecting "Emulate terminal in output console" in the PyCharm "Run/Debug Configurations" window:

    PyCharm Run/Debug Configuration window with "Emulate terminal in output console" selected

    Running directly from the command line, or with the correct setting in PyCharm, results in:

    Kivy application with TextInput objects cut off but visible

    And after nudging the window the text is visible:

    Kivy application with TextInput objects and text visible

    I think resolving the layout issue is a separate problem.