Bill Bridge Bill Bridge - 4 months ago 37
Python Question

from kivy BoxLayout to ScreenManager using .kv file

I have an application with 1 screen in BoxLayout (filename 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()


The examples below have the changes implemented as suggested.

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()


and the following qmscreens.kv file:

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


The example above gives the error message:


AttributeError: 'QmHome' object has no attribute 'elogging'


I guess the code line
elogging = BooleanProperty()
should be changed from the
QManager
to the
QmHome
class. But then I get other errors. So I am completely lost. Your help and directions are highly appreciated.
Thanks in advance.

Answer

Rename all occurrences of the class qmHome to QmHome. By convention across many different languages, beginning of a class should always start with a capital letter.

Kivy not recognizing the screen named with lowercase seems like a bug.