| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 
 |  
import Tkinter as tk
from Tkinter import *
from datetime import * 
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import matplotlib.pylot as plt 
 
class App(tk.Frame):
    def __init__(self, master):
        tk.Frame.__init__(self,master)
        self.master=master
 
        # Create a grid to place our widgets(=buttons,labels...)
        self.grid()
 
        self.buttonPlotPopUp = Button(master=self, text="Plot", command=self.pop_up)
        self.buttonPlotPopUp.grid(column=1)
 
 
    def pop_up(self):
        popUp= Toplevel()
        popUp.title("Plot")
        self.display_plot_in_pop_up()
 
    # theInput has a format : {8: 50870, 17: 115762, 34: 5686}
    # key are unique, don't change it.
    def plot_bar_graph(self):
        theInput={8: 50870, 17: 115762, 34: 5686}
        N = len(theInput) 
        ind = np.arange(N) 
        width = 0.4
        plt.bar(ind, theInput.values(), width, log=True)
        plt.ylabel('y')
        plt.xlabel('x')
        plt.xticks(ind+width/2., theInput.keys(), rotation=90)
        plt.grid()
        plt.show()        
 
    def display_plot_in_pop_up(self):
 
        f=Figure()
        plot=self.plot_bar_graph()
        graph=f.add_subplot(111)
        graph.plot
        canvas=FigureCanvasTkAgg(f)
        canvas.get_tk_widget().grid()
 
root=tk.Tk()
root.title('TelegrammSeeker')
root.geometry('500x500')
app=App(root)
root.mainloop() | 
Partager