通过Kivy按钮调用不同类中的函数

2024-09-24 22:27:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着在kivy中调用一个关于按钮按下的函数,它位于不同于按钮所在的类屏幕中。我也尝试在app类中运行函数,但在那里遇到了问题。下面是我要调用的函数所在的类:

# Main screen with button layout
class LandingScreen(Screen):
    def __init__(self, **kwargs):
        super(LandingScreen, self).__init__(**kwargs)
        self.buttons = [] # add references to all buttons here
        Clock.schedule_once(self._finish_init)

    def ChangePic(self):
        self.buttons[1].background_normal = 'folder.png'

下面是我想用的按钮:

^{pr2}$

为了从这个位置调用ChangePic(),我必须给ChangePic()加上什么前缀?在

或者-有没有一种方法可以从InputScreen类内部轻松处理LandingScreen类中的按钮?在

谢谢!在


Tags: 函数selfapp屏幕initmaindefwith