【问题标题】:object.__init__() takes no arguementsobject.__init__() 不带参数
【发布时间】:2020-04-27 15:46:12
【问题描述】:

所以我目前正在制作一个具有登录功能的应用程序以及其中具有菜单功能的主窗口。当我收到错误时,我遇到了代码问题:

File "C:\Users\Muna Abdullahi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\uix\widget.py", line 350, in __init__ super(Widget, self).__init__(**kwargs) File "kivy\_event.pyx", line 243, in kivy._event.EventDispatcher.__init__ TypeError: object.__init__() takes no arguments

这是我的代码:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty
from kivy.uix.popup import Popup
from kivy.uix.label import Label
from kivy.core.window import Window
from database import DataBase
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.widget import Widget
from kivy.config import Config

Window.clearcolor = (0.5294, 0, 0.3176, 0)

Config.set('kivy', 'keyboard_mode', 'systemandmulti')

class ForgotWindow(Screen):
    namee = ObjectProperty(None)
    email = ObjectProperty(None)

   def VerificationBtn(self):
       pass

   def loginBtn(self):
       sm.current = "login"

class CreateAccountWindow(Screen):
    namee = ObjectProperty(None)
    email = ObjectProperty(None)
    password = ObjectProperty(None)

    def submit(self):
        if self.namee.text != "" and self.email.text != "" and self.email.text.count("@") == 1 and self.email.text.count(".") > 0:
            if self.password != "":
                db.add_user(self.email.text, self.password.text, self.namee.text)

                self.reset()

                sm.current = "login"
           else:
               invalidForm()
       else:
           invalidForm()

   def login(self):
       self.reset()
       sm.current = "login"

   def reset(self):
       self.email.text = ""
       self.password.text = ""
       self.namee.text = ""

   def createBtn(self):
       self.reset()
       sm.current = "create"


class LoginWindow(Screen):
    email = ObjectProperty(None)
    password = ObjectProperty(None)

    def loginBtn(self):
        if db.validate(self.email.text, self.password.text):
            MainWindow.current = self.email.text
            self.reset()
            sm.current = "main"
        else:
            invalidLogin()

    def createBtn(self):
        self.reset()
        sm.current = "create"

    def forgot(self):
        self.reset()
        sm.current = "forgot"

    def reset(self):
        self.email.text = ""
        self.password.text = ""


class MainWindow(BoxLayout):
    pass

class Screen_One(Screen):
    pass

class Screen_Two(Screen):
    pass



class WindowManager(ScreenManager):
    pass


def invalidLogin():
    popup = Popup(title='Invalid Login',
                  content=Label(text='Invalid username or password.'),
                  size_hint=(None, None), size=(400, 400))
    popup.open()


def invalidForm():
    popup = Popup(title='Invalid Form',
                  content=Label(text='Please fill in all inputs with valid information.'),
                  size_hint=(None, None), size=(400, 400))

    popup.open()


kv = Builder.load_file("my.kv")

sm = WindowManager()
db = DataBase("users.txt")

screens = [LoginWindow(name="login"), 
CreateAccountWindow(name="create"),ForgotWindow(name="forgot"), 
MainWindow(name="main"), Screen_One(name="Screen_One"), 
Screen_Two(name="Screen_Two")]
for screen in screens:
    sm.add_widget(screen)

sm.current = "login"


class MyMainApp(App):
    def build(self):
        return sm

if __name__ == "__main__":
    MyMainApp().run() `

如果您也需要我的 kivy 文件,我可以将其发送过来。

有人可以帮我解决这个问题吗?我需要尽快修复代码,因为它是我学校项目的一部分。另外,如果有人能在 Kivy 方面帮助我,那将非常感谢。

【问题讨论】:

  • 请提供一个最小的工作示例! stackoverflow.com/help/minimal-reproducible-example
  • 从错误文本中可以清楚地看出__init__ 不期望该参数。您是否尝试过在此处发布之前调试自己的代码?您至少可以评论导致问题的代码行吗?
  • 这可能是因为您传递了name 关键字参数,但不存在这样的参数名称。您看到的错误是您在这种情况下对 python 的期望。
  • 请隔离导致问题的代码部分,而不是仅仅粘贴整个模块
  • 错误信息没有列出你的任何代码?

标签: python python-3.x python-requests kivy kivy-language


【解决方案1】:

您的MainWindow 类扩展了BoxLayout,但BoxLayout 不支持name 属性。您只需从 MainWindow 创建中删除 name 参数:

MainWindow(name="main")

应该是:

MainWindow()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-22
    • 1970-01-01
    • 2012-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-26
    相关资源
    最近更新 更多