1. <i id='ORE4K'><tr id='ORE4K'><dt id='ORE4K'><q id='ORE4K'><span id='ORE4K'><b id='ORE4K'><form id='ORE4K'><ins id='ORE4K'></ins><ul id='ORE4K'></ul><sub id='ORE4K'></sub></form><legend id='ORE4K'></legend><bdo id='ORE4K'><pre id='ORE4K'><center id='ORE4K'></center></pre></bdo></b><th id='ORE4K'></th></span></q></dt></tr></i><div id='ORE4K'><tfoot id='ORE4K'></tfoot><dl id='ORE4K'><fieldset id='ORE4K'></fieldset></dl></div>
        <bdo id='ORE4K'></bdo><ul id='ORE4K'></ul>

      <small id='ORE4K'></small><noframes id='ORE4K'>

      <legend id='ORE4K'><style id='ORE4K'><dir id='ORE4K'><q id='ORE4K'></q></dir></style></legend>
      1. <tfoot id='ORE4K'></tfoot>

        TypeError: object.__init__() 只接受一个参数(要初始化

        时间:2023-10-10

        • <bdo id='FWjUY'></bdo><ul id='FWjUY'></ul>

          <small id='FWjUY'></small><noframes id='FWjUY'>

            1. <legend id='FWjUY'><style id='FWjUY'><dir id='FWjUY'><q id='FWjUY'></q></dir></style></legend>
                <tbody id='FWjUY'></tbody>

                • <i id='FWjUY'><tr id='FWjUY'><dt id='FWjUY'><q id='FWjUY'><span id='FWjUY'><b id='FWjUY'><form id='FWjUY'><ins id='FWjUY'></ins><ul id='FWjUY'></ul><sub id='FWjUY'></sub></form><legend id='FWjUY'></legend><bdo id='FWjUY'><pre id='FWjUY'><center id='FWjUY'></center></pre></bdo></b><th id='FWjUY'></th></span></q></dt></tr></i><div id='FWjUY'><tfoot id='FWjUY'></tfoot><dl id='FWjUY'><fieldset id='FWjUY'></fieldset></dl></div>
                • <tfoot id='FWjUY'></tfoot>

                  本文介绍了TypeError: object.__init__() 只接受一个参数(要初始化的实例)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试制作一个表单应用程序,但我不明白错误:

                  I am trying to make a form app and I don t understand the error:

                  TypeError: object.__init__() takes exactly one argument (the instance to initialize)
                  

                  代码在这里;

                  class Myapp(App):
                      def build(self):
                          return Grid1()
                  
                  class Grid1(GridLayout):
                      def __init__(self,**kwargs):
                          super(Grid1,self).__init__(**kwargs)
                          self.cols=1
                  
                          self.inside=GridLayout()
                          self.inside.cols=2
                  
                          self.inside.add_widget(Label(text="Your name is :"))
                          self.name=TextInput(multiline=False)
                          self.inside.add_widget(self.name)
                  
                  
                          self.inside.add_widget(Label(text="Your Last name is :"))
                          self.lastname=TextInput(multiline=False)
                          self.inside.add_widget(self.lastname)
                  
                  
                          self.inside.add_widget(Label(text="Your email is :"))
                          self.email=TextInput(multiline=False)
                          self.inside.add_widget(self.email)
                  
                          self.submit=Button(text="Submit",font=40)
                          self.add_widget(self.submit)
                  
                  if __name__=="__main__":
                      Myapp().run()
                  

                  错误

                  File ".kivyprima.py", line 38, in <module> Myapp().run()
                  File "C:UsersAlexAppDataLocalProgramsPythonPython37libsite-packageskivyapp.py", line 829, in run root = self.build()
                  File ".kivyprima.py", line 10, in build return Grid1()
                  File ".kivyprima.py", line 34, in init self.submit=Button(text="Submit",font=40)
                  File "C:UsersAlexAppDataLocalProgramsPythonPython37libsite-packageskivyuixehaviorsutton.py", line 121, in init
                  

                  推荐答案

                  好的,所以错误实际上是 not 在你的 super(Grid1,self).__init__(**kwargs) 语句,它在 Submit 按钮的创建中.你做到了:

                  OK, so the error is actually not in your super(Grid1,self).__init__(**kwargs) statement, it's in the creation of the Submit button. You did:

                  self.submit = Button(text="Submit", font=40)
                  self.add_widget(self.submit)
                  

                  但正如 docs 所说,字体大小是由 font_size 而不是 font 设置.代码应该是:

                  But as the docs say, the font size is set by font_size and not font. The code should be:

                  self.submit = Button(text="Submit", font_size=40)
                  self.add_widget(self.submit)
                  

                  这应该可以正常工作.

                  只想感谢@chepner 指出这一点:

                  Just want to thank @chepner for pointing this out:

                  请注意,问题在于该字体无法被按钮(或其他任何人),只是简单地向上传递,直到它最终传递给 object.__init__ (这会引发错误简单地忽略意想不到的论点).

                  Note that the issue, then, is that font, not being recognized by Button (or anyone else), is simply passed on up the chain until it is ultimately passed to object.__init__ (which raises an error instead of simply ignoring unexpected arguments).

                  这篇关于TypeError: object.__init__() 只接受一个参数(要初始化的实例)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:是否可以在 Kivy 应用程序中读取多个 .kv 文件? 下一篇:问题将 Kivy 设置为全屏

                  相关文章

                  最新文章

                    • <bdo id='WUbbk'></bdo><ul id='WUbbk'></ul>

                    <tfoot id='WUbbk'></tfoot>
                  1. <small id='WUbbk'></small><noframes id='WUbbk'>

                  2. <legend id='WUbbk'><style id='WUbbk'><dir id='WUbbk'><q id='WUbbk'></q></dir></style></legend>
                    <i id='WUbbk'><tr id='WUbbk'><dt id='WUbbk'><q id='WUbbk'><span id='WUbbk'><b id='WUbbk'><form id='WUbbk'><ins id='WUbbk'></ins><ul id='WUbbk'></ul><sub id='WUbbk'></sub></form><legend id='WUbbk'></legend><bdo id='WUbbk'><pre id='WUbbk'><center id='WUbbk'></center></pre></bdo></b><th id='WUbbk'></th></span></q></dt></tr></i><div id='WUbbk'><tfoot id='WUbbk'></tfoot><dl id='WUbbk'><fieldset id='WUbbk'></fieldset></dl></div>