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

时间:2020-06-05 13:18:08

标签: python-3.x matplotlib kivy kivy-language matplotlib-widget

我有一个要制作的应用程序框架。我正在尝试了解“值屏幕”中的按钮如何干扰“方向屏幕”中的绘图。

有可能吗?我无法弄清楚这种“更新”函数的语法,也无法放在哪里(尽管我认为它必须在MyFigure类下)。

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'

1 个答案:

答案 0 :(得分:0)

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