I am trying to achieve something very similar to this question (cannot draw matplotlib chart in tkinter GUI without crashing). The only differences between the code shown in the link and my code are as follows:
-Instead of using canvas.get_tk_widget().pack(...), I am using canvas.get_tk_widget().grid(...).
-For each of my individual frames, I do a columnconfigure and rowconfigure because that's how I organize my GUI elements in each frame.
-My version of Spyder, Matplotlib, and Tkinter are all the latest versions (I'm using Anaconda ontop of it all).
-I don't recieve any sort of warning or error, my console window in Spyder simply stops, and I have to restart my kernel.
I've seen pretty much all tutorials regarding matplotlib and tkinter. At this point I'm ready to give up.
EDIT #2: When I copy and paste this code (https://pythonprogramming.net/how-to-embed-matplotlib-graph-tkinter-gui/), I get the exact same error. This leads me to think that maybe it's something to do with my installations.
EDIT: Skeleton Version of Code/Problem Code
Master App Class:
class iSEEApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.wm_title(self, "GUI V0.5")
container = tk.Frame(self)
container.winfo_toplevel().geometry("600x600")
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (pixelAnnoPage, patchAnnoPage, heatMapPage):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame("pixelAnnoPage")
def show_frame(self, page_name):
frame = self.frames[page_name]
frame.tkraise()
frame.focus_set()
General Frame Class Construction/Convention:
class heatMapPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
self.buildFrame()
def buildFrame(self):
print("test")
#self.pack(fill="both", expand=True)
self.columnconfigure(1, weight = 1)
self.columnconfigure(3, pad = 7)
self.rowconfigure(3, weight = 1)
self.rowconfigure(5, pad = 7)
Problem Code (in buildFrame()):
self.heatFig = Figure(figsize=(5, 4), dpi=100)
self.heatPlot = self.heatFig.add_subplot(111)
self.heatPlot.plot([1,2,3,4,5,6,7,8],[5,6,7,8,1,2,2,1])
self.heatCanvas = FigureCanvasTkAgg(self.heatFig, master=self)
self.heatCanvas.get_tk_widget().grid(row=1, column=0, columnspan=2, rowspan=4, padx=5, sticky="nsew")
self.heatCanvas.show()