无法在不崩溃的情况下在 tkinter GUI 中绘制 matplotlib 图表 [英] cannot draw matplotlib chart in tkinter GUI without crashing

查看:26
本文介绍了无法在不崩溃的情况下在 tkinter GUI 中绘制 matplotlib 图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在通过教程关注此链接:这是我关注的.老哥给你代码.无论如何都将其包含在底部.

I'm currently following this link with a tutorial: Here is the one I am following. The dude gives you the code. Have included it at the bottom anyway.

肯定会推荐.但现在面临的问题:

Would definitely recommend. But now facing issues:

  • 使用 Spyder 2.3.8
  • Python 3.5
  • 一切都是最新的
  • 已将 Spyder 的后端设置为将 matplotlib 读取为TkAgg"(也花了很长时间!).

已标记出导致问题的三行.当这些行不活动时工作正常.激活它们并运行会导致我的终端崩溃并收到消息:

Have hashtagged out the three lines which are causing the issue. Works fine when these lines aren't active. Activating them and running causes my terminal to crash and get the message:

内核似乎意外死亡.使用重启内核"继续使用此控制台.

It seems the kernel died unexpectedly. Use 'Restart kernel' to continue using this console.

我真的一直在到处寻找解决方案.目标是在不崩溃的情况下将图表放入 Tkinter GUI.请帮忙!?

I have really been looking everywhere for a solution. The objective is to get a chart into a Tkinter GUI without it crashing. Please help!?

这是代码,几乎与链接中提供的代码相同:

Here is the code, nearly identical to the one provided in the link:

import matplotlib
#matplotlib.use("TkAgg")

from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,NavigationToolbar2TkAgg
from matplotlib.figure import Figure

import tkinter as tk
import pandas as pd
from tkinter import ttk


LARGE_FONT=("Consolas",12)

class SeaofBTCapp(tk.Tk):

    def __init__(self,*args,**kwargs):
        #
        #tk.Tk.wm_title(self,"")

    print("")
    tk.Tk.__init__(self,*args,**kwargs)
    tk.Tk.wm_title(self,"Hold my Hand")
    tk.Tk.iconbitmap(self,default="1.ico")
    container=tk.Frame(self)
    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 (StartPage,PageThree):
        frame=F(container, self)

        self.frames[F]=frame
        frame.grid(row=0,column=0,sticky="nsew") #north south east west

    self.show_frame(StartPage)

def show_frame(self, cont):
    frame = self.frames[cont]
    frame.tkraise()

def qf(stringtoprint):
    print(stringtoprint)

class StartPage(tk.Frame):
    def __init__(self,parent,controller):
        ttk.Frame.__init__(self,parent)
        label=ttk.Label(self,text="Testing",font=LARGE_FONT)
        label.pack(pady=10,padx=10)

        button3=ttk.Button(self, text="Graph page",
                          command=lambda:controller.show_frame(PageThree))
                          #lambda:controller.show_frame(PageOne))
        button3.pack()

class PageThree(tk.Frame):
    def __init__(self, parent, controller):    
       # app=tk.Tk()
        tk.Frame.__init__(self,parent)
        label=tk.Label(self,text="Graph Page",font=LARGE_FONT)
        label.pack(pady=10,padx=10)

        label1=ttk.Button(self, text="Start Page",
                   command=lambda:controller.show_frame(StartPage))
        label1.pack()

        label1=ttk.Button(self, text="Back to Home",
                   command=lambda:controller.show_frame(StartPage))
        label1.pack()

    #    f=Figure(figsize=(5,5))
    #    a=f.add_subplot(111)
    #    a.plot([1,2,3,4,5,6,7,8],[5,6,7,8,1,2,2,1])
     #   canvas=FigureCanvasTkAgg(f,self)
     #   canvas.show()
     #   canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH,expand=True)

app=SeaofBTCapp()
app.mainloop()

正是以上三六行导致Spyder崩溃.

It's the above three-six lines that cause Spyder to crash.

推荐答案

卸载 conda 版本并通过 pip 安装即可修复.

Uninstalling the conda version and installing it via pip fixes it.

有一个问题:https://github.com/ContinuumIO/anaconda-问题/问题/979

这篇关于无法在不崩溃的情况下在 tkinter GUI 中绘制 matplotlib 图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆