pythonmatplotlibtkinterjupyter-notebookfuzzy-logic

How to insert view function into a Tkinter frame?


I have been following this tutorial: https://pythonhosted.org/scikit-fuzzy/auto_examples/plot_tipping_problem_newapi.html

And now I am trying to create a GUI, I have done everything without problem, but I have not been able to get the view function to be displayed in the same window, it is executed in a new one. This is the line I would like to insert inside a frame:

propina.view(sim=simul_propinas)

This is how it currently looks: Tkinter Window

How can I make it show inside?


Solution

  • If you look into the source code of scikit-fuzzy module, propina.view() is defined as below:

    def view(self, *args, **kwargs):
        """""" + FuzzyVariableVisualizer.view.__doc__
        fig, ax = FuzzyVariableVisualizer(self).view(*args, **kwargs)
        fig.show()
    

    So you can combine the above code with the example on Embedding in Tk to embed the plot into the required tkinter Frame:

    ...
    #matplotlib.use('TkAgg')
    matplotlib.use('Agg')
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
    ...
    def calcular():
        ...
        # don't call propina.view(...)
        #propina.view(sim=simul_propinas)
    
        fig, ax = ctrl.visualization.FuzzyVariableVisualizer(propina).view(sim=simul_propinas)
        canvas = FigureCanvasTkAgg(fig, master=framegraficos)
        canvas.get_tk_widget().pack()
        canvas.draw()
        ...
    

    The result:

    enter image description here