Search code examples
pythonkivykivy-language

First character not getting printed in kivy


I am learning to code in Kivy using python But my Label is not showing the first character Can anyone help me The kv File is as follows:

<MyGrid>
    Label:
        text: "Techy Matanhelia"

The python file is as Follows:

from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label
from kivy.uix.widget import Widget


class MyGrid(Widget):
    pass


class MyApp(App):
    def build(self):
        return MyGrid()


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

Also Can anyone tell me how to edit kivy files on pycharm2020.2.2


Solution

  • That is because your MyGrid class extends Widget. A simple Widget has no capability to handle positioning or sizing of its children, so the Label gets assigned the default size of (100,100) and the default position of (0,0). which results in the first letter of the Label being off the screen. Try making MyGrid extend a Layout, perhaps like this:

    class MyGrid(FloatLayout):
        pass