I am using tkinter to get display a histogram plotted by matplotlib. For some reason though i am getting FigureCanvasTkAgg object has no attribute show but for many it seems to be working. Besides this i even tried using .draw() and i get the error "'NoneType' object has no attribute 'get_tk_widget' "
this is the data
{ "ts": 1393631990, "visitor_uuid": "9a83c97f415601a6", "visitor_username": null, "visitor_source": "external", "visitor_device": "browser"}
{ "ts": 1393631989, "visitor_uuid": "745409913574d4c6", "visitor_username": null, "visitor_source": "external", "visitor_device": "browser"}
{ "ts": 1393631989, "visitor_uuid": "64bf70296da2f9fd", "visitor_username": null, "visitor_source": "internal", "visitor_device": "browser"}
from tkinter import *
import os
import json
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
def openWindowForT2():
with open('Data.json', 'r') as file1:
df= pd.read_json(file1, lines=True)
windowforT2 = Toplevel(window)
# sets the title of the
# Toplevel widget
windowforT2.title("New Window")
# sets the geometry of toplevel
windowforT2.geometry("600x600")
frame = Frame(windowforT2)
frame.place(relx=0.5, rely=0.1,relwidth=0.75 ,relheight=0.1,anchor='n')
nam = Entry(frame,font=40)
nam.place(relwidth=0.65, relheight=1)
button1 = Button(frame, text= "Get graph")
button1.place(relx=0.7,relwidth=0.3,relheight=1)
x1 = df["name"]
plt.hist(x1, density=True, bins=30)
plt.ylabel("time")
plt.xlabel("val")
f = Figure(figsize=(25,15))
canvas = FigureCanvasTkAgg(f,master = windowforT2).show()
canvas.get_tk_widget().pack(side= TOP, fill=BOTH,expand=True)
if i just do plt.show() im able to see that histogram is being produced but i want it to be inside the tkinter window. can someone tell me why this is causing an error?