1 回答

TA貢獻1786條經驗 獲得超13個贊
ScrollView僅當其子項 (the GridLayout) 大于 時才會滾動ScrollView。此外,該行:
height: self.minimum_height
除非您添加以下行,否則將無效:
size_hint_y: None
row_default_height您可以通過為指定 aGridLayout并為 消除 來size_hint_y=None增加繪圖的大小FigureCanvasKivyAgg。因此,我建議將您指定ScrollView為:
ScrollView:
id: plot_scroll
do_scroll_y: True
do_scroll_x: False
pos_hint: {"top": .68}
plot_layout: plot_layout
GridLayout:
id: plot_layout
cols: 1
size_hint_y: None
row_default_height: 500 # any default row height that you desire
height: self.minimum_height
然后,使用以下方法添加繪圖:
def add_sp_plot(self, date_from, date_to):
# There were too many lines of data handling and plot creating, so I've only left the KivyPart:
# ------- KIVY part ------- KIVY part ------- KIVY part ------- KIVY part ------- #
self.plot_scroll.plot_layout.clear_widgets()
self.plot_scroll.plot_layout.add_widget(FigureCanvasKivyAgg(plt.gcf()))
self.plot_scroll.plot_layout.add_widget(FigureCanvasKivyAgg(plt.gcf()))
self.plot_scroll.plot_layout.add_widget(FigureCanvasKivyAgg(plt.gcf()))
刪除size_hint_y=None保留默認值size_hint_yas 1,以便繪圖將占用GridLayout分配給它的所有空間 (the row_default_height)。
添加回答
舉報