使用 KIVY 集体卡在加载窗口
Posted
技术标签:
【中文标题】使用 KIVY 集体卡在加载窗口【英文标题】:Stuck in loading window collectively using KIVY 【发布时间】:2021-01-13 20:54:26 【问题描述】:我正在学习使用 Python 和 Kivy 的 POS 教程,但我遇到了这个似乎消失并不断重现的错误。我有一个 main.py 文件,我尝试在其中加载一个引发属性错误的窗口 admin.py
File "C:/Users/John/PycharmProjects/FirstKivyApplication/main.py", line 3, in <module>
from Admin.admin import AdminWindow
File "C:\Users\John\PycharmProjects\FirstKivyApplication\Admin\admin.py", line 22, in <module>
Builder.load_file('Admin/admin.kv')
File "C:\Users\John\PycharmProjects\FirstKivyApplication\lib\site-packages\kivy\lang\builder.py", line 301, in load_file
return self.load_string(data, **kwargs)
File "C:\Users\John\PycharmProjects\FirstKivyApplication\lib\site-packages\kivy\lang\builder.py", line 399, in load_string
widget = Factory.get(parser.root.name)(__no_builder=True)
File "C:\Users\John\PycharmProjects\FirstKivyApplication\lib\site-packages\kivy\factory.py", line 130, in __getattr__
raise AttributeError
AttributeError
MAIN.PY
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from Admin.admin import AdminWindow
from Signin.signin import SignInWindow
from Operator.theoperator import OperatorWindow
class MainWindow(BoxLayout):
admin_widget = AdminWindow() #An instance of our Admin wdindow
signin_widget = SignInWindow() # An instance of our sign in window
operator_widget = OperatorWindow() # An instance of our Operator window
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.ids.scrn_si.add_widget(self.signin_widget)
self.ids.scrn_admin.add_widget(self.admin_widget)
self.ids.scrn_op.add_widget(self.operator_widget)
class MainApp(App):
def build(self):
return MainWindow()
if __name__ == "__main__":
sa = MainApp()
sa.run()
管理员.PY
from kivy.uix.modalview import ModalView
from kivy.lang import Builder
Builder.load_file('Admin/admin.kv')
class Notify(ModalView):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.size_hint = (.3, .3)
class AdminWindow(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def logout(self):
self.parent.parent.current = 'scrn_si'
class AdminApp(App):
def build(self):
return AdminWindow()
if __name__ == '__main__':
AdminApp().run()
这是我的项目结构:
【问题讨论】:
【参考方案1】:我在相关的 kv 文件中忘记了下面的这句话。
#: import Window kivy.core.window.Window
【讨论】:
以上是关于使用 KIVY 集体卡在加载窗口的主要内容,如果未能解决你的问题,请参考以下文章