Search code examples
pythonpython-3.xkivykivy-language

Getting a"TypeError: object.__init()__ takes no arguments


I am trying to implement the graphical part of a game that I wrote using kivy. Since I am new to kivy I went through ts documentation which I found some programming samples that I studied and used. In one of the samples, I get:

TypeError: object.__init__() takes no parameters

Here is the code:

from kivy.app import App;
from kivy.uix.label import Label;
from kivy.uix.gridlayout import GridLayout;
from kivy.uix.textinput import TextInput;

class LoginScreen(GridLayout):
    def __init__(self, **kwargs):

        #super(LoginScreen, self).__new__(**kwargs) # == super(LoginScreen, self).__init__(**kwagrs) 
        #GridLayout.__init__()
        super().__init__(**kwargs);
        self.cols = 2 # The colors

        # Creating the Object for username and then adding it into Canvans 
        self.add_widget(Label(text="Username: "))
        self.username = TextInput(multiline=False)
        self.add_widget(self.username)

        # Creating the Object for password and then adding it into Canvans
        self.add_widget(None,Label(Text="password:"))
        self.password = TextInput(password=True,multiline=False)
        self.add_widget(self.password)

class SimpleKivy(App):
    def build(self):
        return LoginScreen();

if __name__ == "__main__":
    SimpleKivy().run();

Solution

  • The error is on this line:

    self.add_widget(None,Label(Text="password:"))
    

    You don't need to use None, and change Text= to text= because kivy's keyword args are all lowercase. So change it to:

    self.add_widget(Label(text="password:"))
    

    Also, have a look at Kv language it is useful for building apps with kivy.