Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
970 views
in Technique[技术] by (71.8m points)

kivy - Python: changing screens via function

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...