我在 BoxLayout 中有一个带有 1 个屏幕的应用程序(文件名 qmscreens.py)。
from kivy.app import App
from kivy.core.window import Window
class qmHome(BoxLayout):
pass
class qmscreensApp(App):
def build(self):
Window.clearcolor = (1,1,1,1)
Window.size = (500, 500)
homeWin = qmHome()
return homeWin
qmscreensApp().run()
下面的示例按照建议实施了更改。
from kivy.app import App
from kivy.core.window import Window
from kivy.uix.screenmanager import ScreenManager, Screen
class EditImage(Screen):
pass
class QmHome(Screen):
pass
class QManager(ScreenManager):
elogging = BooleanProperty()
elogging = True
# and a lot of other python code here below
class qmscreensApp(App):
def build(self):
Window.clearcolor = (1,1,1,1)
Window.size = (500, 500)
homeWin = QManager()
return homeWin
qmscreensApp().run()
以及以下 qmscreens.kv 文件:
QManager:
QmHome:
EditImage:
<QmHome>:
name: 'home'
Button:
on_press: app.root.current = 'edit'
text: 'to edit screen'
font_size: 50
<EditImage>:
name: 'edit'
Button:
on_release: app.root.current = 'home'
text: 'back to the home screen'
font_size: 50
CheckBox:
id: _evlogg_cb
active: root.elogging
上面的示例给出了错误消息:
AttributeError:“QmHome”对象没有属性“elogging”
我猜代码行elogging = BooleanProperty()
应该从类更改QManager
为QmHome
。但后来我得到了其他错误。所以我完全迷路了。非常感谢您的帮助和指导。提前致谢。