I want to reduce my code via general function for changing screens.
my screens have names as numbers e.g name: "2"..
when you click on certain list in bottomsheet I want to changing certain screen.
in .py
def show_bottom_sheet(self):
bs = MDListBottomSheet()
bs.add_item("Models", lambda x: x,icon='account-group-outline')
for y in 1,2,3,4,12,13,14,21,23,24,31,32,34,41,42,43,123,124,134,234:
bs.add_item(f"example {y} ", lambda x= y: self.behavior(x), icon='account-group-outline')
bs.open()
def behavior(self, x):
self.manager.current = str(x)
before my changes it was like this, but for every single number and it was too useless
def behavior2(self):
self.manager.current = "2"
I tried it like this but it gives me this error
File "C:UsersStankoPycharmProjectspythonProjectvenvlibsite-packageskivyuixscreenmanager.py", line 1064, in get_screen
raise ScreenManagerException('No Screen with name "%s".' % name)
kivy.uix.screenmanager.ScreenManagerException: No Screen with name "<kivymd.uix.list.OneLineIconListItem object at 0x0AADB088>".
question from:
https://stackoverflow.com/questions/66063283/python-changing-screens-via-function 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…