Reputation: 13
I developed an app with python and faced this problem:
TypeError: object.__init__() takes no parameters
My files are the following :
Main.py
:from kivy.app import App
from kivy.lang import Builder
from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import Screen
from kivy.uix.button import ButtonBehavior
from kivy.uix.image import Image
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from clinics.clinicsbanner import ClinicBanner
import psycopg2
class HomeScreen(Screen):
pass
class SettingsScreen(Screen):
pass
class InfoScreen(Screen):
pass
class ResultScreen(Screen):
pass
class ImageButton(ButtonBehavior, Image):
pass
GUI = Builder.load_file('main.kv')
class MainApp(App):
def build(self):
return GUI
def on_start(self):
result_banner = self.root.ids['result_screen'].ids['result_banner']
con = psycopg2.connect(
host="localhost",
database="here is my db",
user="here is my user",
password="here is my password")
cur = con.cursor()
city = self.root.ids['home_screen'].ids.city.text
cur.execute("SELECT * FROM clinic WHERE city='%s'" %city)
rows = cur.fetchall()
for row in rows:
C = ClinicBanner(cities=row[1])
result_banner.add_widget(C)
con.commit()
cur.close()
con.close()
clinicbanner.py
:from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
class ClinicBanner(GridLayout):
rows = 1
def __init__(self, **kwargs):
super(ClinicBanner, self).__init__(**kwargs)
centre = FloatLayout()
centre_label = Label(text=kwargs['cities'], size_hint=(1, .2), pos_hint={"top": .2, "left": 1})
centre.add_widget(centre_label)
self.add_widget(centre)
I think it may be connected with database or clinicbanner.py
file, in super function.
I believe that you can help me.
Thank you for your answers and help !
Upvotes: 0
Views: 213
Reputation: 1455
As inclement stated out correctly you pass an argument to the class that does not exist C = ClinicBanner(cities=row[1])
. It is the cities argument. If you use it this way you better write your init method like this:
def __init__(self, cities, **kwargs):
super(ClinicBanner, self).__init__(**kwargs)
centre = FloatLayout() centre_label = Label(text=cities, size_hint=(1, .2), pos_hint={"top": .2, "left": 1})
I added cities to the init method as an argument and changed the labels text to cities (I assume cities is a str). This way it should work, but if you create a new instance of ClinicBanner you now always have to add a cities argument. If you dont want that you can change the init method to def __init__(self, cities="", **kwargs):
to add an empty string as default. I hope, it now works for you.
Upvotes: 1
Reputation: 29460
The error means you're passing arguments to the superclass that it does not expect. In this case it's probably the cities
argument, but I didn't look closely. Don't pass the argument to the parent because the parent doesn't have anything to do with it.
Upvotes: 0