I'm following a tutorial on youtube and when I run the code, the window shows the labels half off the screen on the left-bottom side. I uploaded a screenshot of the window.
The .kv file is:
<MyGrid>
GridLayout:
cols: 1
GridLayout:
cols: 2
Label:
text: "Name: "
TextInput:
multiline:False
Label:
text: "Email: "
TextInput:
multiline:False
Button:
text: "Submit"
And the py file is:
from kivy.app import App
from kivy.uix.widget import Widget
class MyGrid(Widget):
pass
class MyApp (App):
def build(self):
return MyGrid()
if __name__ == "__main__":
MyApp().run()
CodePudding user response:
You are trying to use the base Widget
class as a container, but it was not designed for that use. Try just using some Layout
class as the base for MyGrid
, like this:
class MyGrid(FloatLayout):
pass
Note that this will result in a GUI that is a FloatLayout
that contains a GridLayout
which contains another GridLayout
. If that is not your intention, consider changing the base class of MyGrid
to GridLayout
and eliminate one or two of the contained GridLayouts
.