python kivy实例_Kivy:应用程序中的实例无效。

我对Python和Kivy都是新手,这是我的第一个小项目,不知道我做错了什么,下面是pydev(eclipse)的日志:[INFO ] Kivy v1.8.0

[INFO ] [Logger ] Record log in C:\Users\Sudheer.kivy\logs\kivy_14-06-21_10.txt

[INFO ] [Factory ] 157 symbols loaded

[DEBUG ] [Cache ] register with limit=None, timeout=Nones

[DEBUG ] [Cache ] register with limit=None, timeout=60s

[DEBUG ] [Cache ] register with limit=None, timeout=Nones

[INFO ] [Image ] Providers: img_tex, img_dds, img_pygame, img_gif (img_pil ignored)

[DEBUG ] [Cache ] register with limit=1000, timeout=60s

[DEBUG ] [Cache ] register with limit=1000, timeout=3600s

[INFO ] [Text ] Provider: pygame

[DEBUG ] [Cache ] register with limit=500, timeout=60s

[INFO ] [Loader ] using a thread pool of 2 workers

[DEBUG ] [Cache ] register with limit=None, timeout=60.0s

[DEBUG ] [Cache ] register with limit=None, timeout=60.0s

[DEBUG ] [App ] Loading kv

[DEBUG ] [App ] kv not found

[CRITICAL ] App.root must be an instance of Widget

Traceback (most recent call last):

File “D:\OS Files\workspace\Kal__main__.py”, line 9, in

MyClass().run()

File “C:\Kivy180\kivy\kivy\app.py”, line 772, in run

raise Exception(‘Invalid instance in App.root’)

Exception: Invalid instance in App.root

代码文件结构如下:

python kivy实例_Kivy:应用程序中的实例无效。

代码如下:

文件:main.pyfrom Src.AppStart import MyClass

if name == ‘main‘:

MyClass().run()

文件: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: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是一个无效的实例吗

Original: https://blog.csdn.net/weixin_29374899/article/details/113638678
Author: 滴水吞舟
Title: python kivy实例_Kivy:应用程序中的实例无效。

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/782749/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球