如何将变量从一个类传递到另一类?

时间:2020-07-15 09:06:46

标签: python class variables instance

我是python的新手,最近使用kivy开发了一个应用程序。现在,我正在尝试将方法在一个类中创建的变量传递给下一个类,但无法弄清楚该怎么做。

这是我的第一堂课,基本上只是告诉我当前三个按钮中的哪个被按下:

class InputParameters(GridLayout):

    verfahren = ObjectProperty(None)

    def on_state(self, togglebutton):
        tb = togglebutton
        if tb.state == 'down':
            self.verfahren = tb.text
            print(self.verfahren)
            return self.verfahren

我得到了选定的值,因此该方法有效,现在我试图在此类中实例化选定的值,但是我不确定如何:

class StatusBar(BoxLayout):
    #InputGrößen
    group_mode = False
    prozess = ObjectProperty(None)
    vorbehandlung = ObjectProperty(None)
    material = ObjectProperty(None)
    haerte = ObjectProperty(None)
    rauheit = ObjectProperty(None)

    def btn_submit(self):

        ip = App.get_running_app().root.ids._input_parameters
        op = App.get_running_app().root.ids._output_parameters

        print("Haerte:", ip.haerte.value, "Rauheit:", ip.rauheit.value, "Material:", ip.material.text, "Vorbehandlung:", ip.vorbehandlung.text)

第一步,我只想在按下提交按钮时将值打印到控制台。这适用于显示的代码。但是我不知道如何在verfahren的方法btn_submit中使用变量class(StatusBar(BoxLayout)。希望您能提供帮助,这应该很容易,但是我绝对是新手...

0 个答案:

没有答案