单击KivyMD中的按钮后,如何在布局中添加图?

时间:2020-05-06 19:56:13

标签: python plot kivy

我在将布局添加到布局时遇到问题。我不知道如何将按钮与BoxLayouts连接。我为每个BoxLayout赋予了特殊的 id ,但现在不知道该怎么办。我只想在单击按钮后显示一些图。这是我的代码:

import kivy
from kivy.lang import Builder

from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg
from kivymd.app import MDApp
import matplotlib.pyplot as plt

KV = '''
GridLayout:
    cols:2

    BoxLayout:
        orientation: "vertical"
        id: plot1
        MDLabel:
            text:"I want to put a plot here"
            halign: "center"

    BoxLayout:
        orientation: "vertical"
        id: plot2
        MDLabel:
            text:"I want to put a plot here"
            halign: "center"

    BoxLayout:
        orientation: "vertical"
        id: plot3
        MDLabel:
            text:"I want to put a plot here"
            halign: "center"


    FloatLayout:
        MDFloatingActionButton:
            pos_hint: {'center_x': .9, 'center_y': .15}
            icon:"chart-bell-curve-cumulative"
            on_release: app.show_plot()
'''

class Main(MDApp):

    def build(self):
        return Builder.load_string(KV)

    def show_plot(self):
        #some plots to show
        pass

Main().run()

对于此问题的任何建议,我将不胜感激。

0 个答案:

没有答案
相关问题