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

    <tfoot id='xNNQe'></tfoot>
  • <legend id='xNNQe'><style id='xNNQe'><dir id='xNNQe'><q id='xNNQe'></q></dir></style></legend>

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

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

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

        TypeError: object.__init__() takes exactly one argument (the instance to initialize)(TypeError: object.__init__() 只接受一个参数(要初始化的实例))
      2. <small id='t4Y91'></small><noframes id='t4Y91'>

        <legend id='t4Y91'><style id='t4Y91'><dir id='t4Y91'><q id='t4Y91'></q></dir></style></legend>
          • <bdo id='t4Y91'></bdo><ul id='t4Y91'></ul>
              <tbody id='t4Y91'></tbody>

              <tfoot id='t4Y91'></tfoot>

                <i id='t4Y91'><tr id='t4Y91'><dt id='t4Y91'><q id='t4Y91'><span id='t4Y91'><b id='t4Y91'><form id='t4Y91'><ins id='t4Y91'></ins><ul id='t4Y91'></ul><sub id='t4Y91'></sub></form><legend id='t4Y91'></legend><bdo id='t4Y91'><pre id='t4Y91'><center id='t4Y91'></center></pre></bdo></b><th id='t4Y91'></th></span></q></dt></tr></i><div id='t4Y91'><tfoot id='t4Y91'></tfoot><dl id='t4Y91'><fieldset id='t4Y91'></fieldset></dl></div>
                • 本文介绍了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__() 只接受一个参数(要初始化的实例)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Kivy 1.9.0 Windows package KeyError: #39;rthooks#39;(Kivy 1.9.0 Windows 包 KeyError: rthooks)
                  Python Kivy: how to call a function on button click?(Python Kivy:如何在按钮单击时调用函数?)
                  How to disable a widget in Kivy?(如何禁用 Kivy 中的小部件?)
                  Centering an object in Kivy(在 Kivy 中将对象居中)
                  How to downgrade to Python 3.4 from 3.5(如何从 Python 3.5 降级到 Python 3.4)
                  Change button or label text color in kivy(在kivy中更改按钮或标签文本颜色)

                      <bdo id='CsoWG'></bdo><ul id='CsoWG'></ul>
                    • <legend id='CsoWG'><style id='CsoWG'><dir id='CsoWG'><q id='CsoWG'></q></dir></style></legend>
                          <tfoot id='CsoWG'></tfoot>

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

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

                              <tbody id='CsoWG'></tbody>