获取TypeError:object .__ init __()不带参数Kivy [英] Getting TypeError: object.__init__() takes no parameters Kivy

查看:52
本文介绍了获取TypeError:object .__ init __()不带参数Kivy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用python开发了一个应用程序,并遇到了这个问题:

I developed an app with python and faced this problem:

TypeError: object.__init__() takes no parameters

我的文件如下:

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)

我认为它可能与数据库或clinicbanner.py文件具有超级功能.

I think it may be connected with database or clinicbanner.py file, in super function.

我相信您可以帮助我.

感谢您的回答和帮助!

推荐答案

该错误表示您正在将参数传递给它不期望的超类.在这种情况下,可能是cities参数,但我没有仔细观察.不要将参数传递给父母,因为父母与它没有任何关系.

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.

这篇关于获取TypeError:object .__ init __()不带参数Kivy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆