Python 3.6.4 / Pycharm IDE
I was studying the kivy library and the error occurred while trying to replicate the code below:
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
class LoginScreen(GridLayout):
def __init__(self, **kwargs):
super(LoginScreen, self).__init__(**kwargs)
self.cols = 2
self.add_widget(Label(text='User Name'))
username = TextInput(multiline=False)
self.add_widget(self.username)
self.add_widget(Label(text='password'))
password = TextInput(password=True, multiline=False)
self.add_widget(self.password)
class MyApp(App):
def build(self):
return LoginScreen()
if __name__ == '__main__':
LoginScreen().run()
O error que aparece foi:
File "D:/Users/Usuario/PycharmProjects/eXcript/main.py", line 40, in <module>
LoginScreen().run()
File "D:/Users/Usuario/PycharmProjects/eXcript/main.py", line 30, in __init__
self.add_widget(self.username)
AttributeError: 'LoginScreen' object has no attribute 'username'