1 2 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 54
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
# Gui modules
import tkinter as tk
import tkinter.ttk
import tkinter.messagebox
# Plotting modules
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
class MainApplication(tk.Frame):
"""Main frame of the user interface. Parent is root."""
def __init__(self, master, *args, **kwargs):
tk.Frame.__init__(self, master, *args, **kwargs)
self.master = master
self.initialize()
def initialize(self):
# Frame to hold content
frame = tk.Frame(self, name='polar')
frame.pack(fill=tk.BOTH, expand=tk.Y, padx=2, pady=3)
# Set up a figure in a canvas
self.figure = plt.figure(1)
self.canvas = FigureCanvasTkAgg(self.figure, master=frame)
self.canvas.get_tk_widget().config(height=40, width=200)
self.canvas.get_tk_widget().pack(fill='both', expand=1, padx=2, pady=2)
#self.canvas.draw()
def stop_gui():
"""Function called to cleanly stop the interface"""
if tkinter.messagebox.askokcancel('Quit', 'Do you want to quit?'):
root.quit()
root.destroy()
if __name__ == '__main__':
root = tk.Tk()
root.resizable(0,0)
root.configure(background='black')
root.title('App')
MainApplication(root).pack()
root.protocol("WM_DELETE_WINDOW", stop_gui)
root.mainloop() |
Partager