Reputation: 17
I am new to kivy and using some tutorials but i only get black screen while on the videos developers get their widget on the screen.
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
class MyGrid(GridLayout):
def __int__(self, **kwargs):
super(MyGrid, self).__int__(**kwargs)
self.cols = 2
self.add_widget(Label(text="Name: "))
self.name = TextInput(multiline=False)
self.add_widget(self.name)
self.add_widget(Label(text="last name : "))
self.lastName = TextInput(multiline=False)
self.add_widget(self.lastname)
self.add_widget(Label(text="email: "))
self.emailName = TextInput(multiline=False)
self.add_widget(self.emailname)
class MyApp(App):
def build(self):
return MyGrid()
if __name__ == "__main__":
MyApp().run()
Upvotes: 1
Views: 191
Reputation: 2231
You have some spelling errors in the code.
The first is about the __init__
function that you spelled __int__
You also use a different variable to assign a widget and a similar one (but different) for adding it (e.g. self.lastName = TextInput(multiline=False)
and self.add_widget(self.lastname)
)
This code should work:
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
class MyGrid(GridLayout):
def __init__(self, **kwargs):
super(MyGrid, self).__init__(**kwargs)
self.cols = 2
self.add_widget(Label(text="Name: "))
self.name = TextInput(multiline=False)
self.add_widget(self.name)
self.add_widget(Label(text="last name : "))
self.lastName = TextInput(multiline=False)
self.add_widget(self.lastName)
self.add_widget(Label(text="email: "))
self.emailName = TextInput(multiline=False)
self.add_widget(self.emailName)
class MyApp(App):
def build(self):
return MyGrid()
if __name__ == '__main__':
MyApp().run()
Upvotes: 1