Error in matplotlib popup window (AttributeError: 'NoneType' object has no attribute 'set_canvas')

后端 未结 2 1589
被撕碎了的回忆
被撕碎了的回忆 2020-12-22 03:31

I tried to plot the graph in pop up window. It pops up. But there is an error.

import tkinter as tk
window = tk.Tk()
window.configure(background=\'white\')

         


        
2条回答
  •  失恋的感觉
    2020-12-22 03:56

    You didn't show how you create your class for plotting, so i can only go by assumption here. First create a empty list:

    import tkinter as tk
    window = tk.Tk()
    window.configure(background='white')
    figure_holder = []
    

    Then append to the list when you create your figure:

    def plot_sheets(self):
        for i in range(len(self.sheets)):
            a = self.sheets[i].plot_sheet()
            figure_holder.append(a)
    

    Retrieve the figure object from the list when you plot it:

    def cal_culate1():
    
        fig = figure_holder[0]
    
        dataPlot = FigureCanvasTkAgg(fig, master = window)
        #dataPlot.show()
        dataPlot.get_tk_widget().pack(side='top', fill='both', expand=1)
    

提交回复
热议问题