我可以使用一个屏幕上的按钮来更改另一个屏幕吗?

Can I use buttons from one screen to make changes to other screen?

我有一个要制作的应用程序的框架。我试图了解 "values screen" 中的按钮如何干扰 "direction screen" 中的情节。

这可能吗?我无法弄清楚这样一个 "update" 函数的语法,也不知道把它放在哪里(尽管我认为它必须在 MyFigure class 下)。

main.py 是

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg
import matplotlib.pyplot as plt


class AppScreen(BoxLayout):
    pass

class MagneticFieldApp(App):
    def build(self):
        return AppScreen()

class MyFigure(FigureCanvasKivyAgg):
    def __init__(self, **kwargs):
        plt.plot([1, 23, 2, 25])
        plt.ylabel('some numbers')
        super().__init__(plt.gcf(), **kwargs)

    #def plotx2(self):

    #def plotx3(self):

if __name__ == "__main__":
    MagneticFieldApp().run()

magneticfield.kv 是

<ValuesScreen@Screen>:

<DirectionScreen@Screen>:

<IntensityScreen@Screen>:
    Label:
        text: 'intensity'
        font_size:50

<AppScreen>:
    spacing: 5
    orientation: 'vertical'
    manager: manager

    ScreenManager:
        size_hint: 1 , .9
        pos_hint: {'top': 1}
        id: manager

        ValuesScreen:
            name: 'valuesscreen'
            GridLayout:
                cols: 1
                Button:
                    text: 'x**2'
                    #on_press:

                Button:
                    text: 'x**3'
                    #on_press:

        DirectionScreen:
            name: 'directionscreen'
            MyFigure:

        IntensityScreen:
            name: 'intensityscreen'

    GridLayout:
        size_hint: 1 , .1
        pos_hint: {'y': 0}
        rows:1

        Button:
            text: 'values'
            on_press:
                root.manager.current = 'valuesscreen'

        Button:
            text: 'direction'
            on_press:
                root.manager.current = 'directionscreen'

        Button:
            text: 'intensity'
            on_press:
                root.manager.current = 'intensityscreen'

你可以使用 app.root.get_screen('directionscreen').plotx2() 但我不能更精确,因为我不明白你想做什么 :)