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

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

        <legend id='M7YMf'><style id='M7YMf'><dir id='M7YMf'><q id='M7YMf'></q></dir></style></legend>
      1. Kivy:App.root 中的无效实例

        时间:2023-10-09

        • <legend id='x4Bmn'><style id='x4Bmn'><dir id='x4Bmn'><q id='x4Bmn'></q></dir></style></legend>

              <tbody id='x4Bmn'></tbody>

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

              • <i id='x4Bmn'><tr id='x4Bmn'><dt id='x4Bmn'><q id='x4Bmn'><span id='x4Bmn'><b id='x4Bmn'><form id='x4Bmn'><ins id='x4Bmn'></ins><ul id='x4Bmn'></ul><sub id='x4Bmn'></sub></form><legend id='x4Bmn'></legend><bdo id='x4Bmn'><pre id='x4Bmn'><center id='x4Bmn'></center></pre></bdo></b><th id='x4Bmn'></th></span></q></dt></tr></i><div id='x4Bmn'><tfoot id='x4Bmn'></tfoot><dl id='x4Bmn'><fieldset id='x4Bmn'></fieldset></dl></div>
                <tfoot id='x4Bmn'></tfoot>
                  <bdo id='x4Bmn'></bdo><ul id='x4Bmn'></ul>
                  本文介绍了Kivy:App.root 中的无效实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我是 Python 和 Kivy 的新手,这是我的第一个小项目,不知道我做错了什么,以下是来自 pydev(eclipse) 的日志:

                  I am new to Python as well as Kivy, this is my first small project, and don't know what I did wrong, following is the log from pydev(eclipse):

                  [INFO              ] Kivy v1.8.0
                  [INFO              ] [Logger      ] Record log in C:UsersSudheer.kivylogskivy_14-06-21_10.txt
                  [INFO              ] [Factory     ] 157 symbols loaded
                  [DEBUG             ] [Cache       ] register <kv.lang> with limit=None, timeout=Nones
                  [DEBUG             ] [Cache       ] register <kv.image> with limit=None, timeout=60s
                  [DEBUG             ] [Cache       ] register <kv.atlas> with limit=None, timeout=Nones
                  [INFO              ] [Image       ] Providers: img_tex, img_dds, img_pygame, img_gif (img_pil ignored)
                  [DEBUG             ] [Cache       ] register <kv.texture> with limit=1000, timeout=60s
                  [DEBUG             ] [Cache       ] register <kv.shader> with limit=1000, timeout=3600s
                  [INFO              ] [Text        ] Provider: pygame
                  [DEBUG             ] [Cache       ] register <kv.loader> with limit=500, timeout=60s
                  [INFO              ] [Loader      ] using a thread pool of 2 workers
                  [DEBUG             ] [Cache       ] register <textinput.label> with limit=None, timeout=60.0s
                  [DEBUG             ] [Cache       ] register <textinput.width> with limit=None, timeout=60.0s
                  [DEBUG             ] [App         ] Loading kv <D:OS FilesworkspaceKalSrcmyclass.kv>
                  [DEBUG             ] [App         ] kv <D:OS FilesworkspaceKalSrcmyclass.kv> not found
                  [CRITICAL          ] App.root must be an _instance_ of Widget
                   Traceback (most recent call last):
                     File "D:OS FilesworkspaceKal\__main__.py", line 9, in <module>
                       MyClass().run()    
                     File "C:Kivy180kivykivyapp.py", line 772, in run
                       raise Exception('Invalid instance in App.root')
                   Exception: Invalid instance in App.root
                  

                  代码文件结构如下:

                  代码如下:文件:ma​​in.py

                  Codes are as follows: File:main.py

                  from Src.AppStart import MyClass
                  
                  if __name__ == '__main__':
                      MyClass().run()    
                  

                  文件:AppStart.py:

                  File:AppStart.py:

                  from kivy.app import App
                  from Src.Logins.LoginForm import LoginForm
                  from kivy.uix.button import Button
                  
                  class MyClass(App):
                      '''
                      classdocs
                      '''
                      def build(self):
                          c=LoginForm
                          #c=Button(text="Checked")
                          return c
                  

                  文件:LoginForm.py:

                  File:LoginForm.py:

                  from kivy.uix.gridlayout import GridLayout
                  from kivy.graphics import Color
                  from kivy.uix.label import Label
                  from kivy.uix.textinput import TextInput
                  
                  class LoginForm(GridLayout):
                      '''
                      classdocs
                      '''
                      def __init__(self, **kwargs):
                          #kwargs['cols'] = 1
                  
                          #Layout=GridLayout(cols=2, rows=3, background_color=Color(1,1,1))
                          self.cols=2
                          self.rows=3
                          self.background_color=Color(1,1,1)
                  
                          IDlbl =Label(text="User ID: ")
                          PWlbl =Label(text="Password: ")
                          IDtxtbox = TextInput(text="",multiline=False)
                          PWtxtbox = TextInput(text="",multiline=False, password=True)
                  
                          self.add_widget(IDlbl)
                          self.add_widget(PWlbl)
                          self.add_widget(IDtxtbox)
                          self.add_widget(PWtxtbox)
                          #return Layout
                          super(LoginForm, self).__init__(**kwargs)
                  

                  能否请您告诉我为什么 App.root 是无效实例,

                  Could you please let me know why is App.root is an invalid instance,

                  推荐答案

                  App.build()的返回值赋值为App.root.在您的 build() 中,您返回一个类 (LoginForm) 而不是该类的实例.只需将 build() 中的那一行更改为 c = LoginForm() 即可修复它.

                  The return value of App.build() is assigned as App.root. In your build() you return a class (LoginForm) instead of an instance of the class. Simply changing that line in build() to c = LoginForm() should fix it.

                  这篇关于Kivy:App.root 中的无效实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何将一个属性绑定到 Kivy 中的另一个属性? 下一篇:如何从 Python 代码文件中设置 kivy 小部件 id

                  相关文章

                  最新文章

                  1. <small id='JpMqN'></small><noframes id='JpMqN'>

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

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

                      <legend id='JpMqN'><style id='JpMqN'><dir id='JpMqN'><q id='JpMqN'></q></dir></style></legend>
                    2. <tfoot id='JpMqN'></tfoot>