-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
93 lines (69 loc) · 2.44 KB
/
main.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import tkinter
import os
import matplotlib
import tkinter as tk
from waitress import serve
from flask import *
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello, World!'
@app.route('/data', methods=['POST'])
def handle_post():
data =(request.json) # get data sent in the POST request
print(data['test'])
os.exit()# print the data to console
return 'Success', 200
app.run(host="0.0.0.0")
matplotlib.use('TkAgg')
# from matplotlib import style
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
import customtkinter
import gunicorn
def app(environ, start_response):
data = b"Hello, World!\n"
start_response("200 OK", [
("Content-Type", "text/plain"),
("Content-Length", str(len(data)))
])
return iter([data])
class GraphPage(tk.Frame):
def __init__(self, parent, period):
tk.Frame.__init__(self, parent)
self.title_label = tk.Label(self, text=f"Moisture over {period}")
self.title_label.pack()
self.pack()
def add_mpl_figure(self, fig):
self.mpl_canvas = FigureCanvasTkAgg(fig, self)
self.mpl_canvas.draw()
self.mpl_canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=True)
self.toolbar = NavigationToolbar2Tk(self.mpl_canvas, self)
self.toolbar.update()
self.mpl_canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
class MPLGraph(Figure):
def __init__(self):
Figure.__init__(self, figsize=(5, 5), dpi=100)
self.plot = self.add_subplot(111)
self.plot.plot([1, 2, 3, 4, 5, 6, 7], [4, 3, 5, 0, 2, 0, 6])
class App(tkinter.Tk):
def __init__(self):
super().__init__()
self.geometry("400x150")
self.button = customtkinter.CTkButton(self, text="Generate Report", command=self.button_callbck)
self.button.pack(padx=20, pady=20)
self.period = "1 Week"
combobox = customtkinter.CTkComboBox(self, values=["1 Day", "1 Week"],
command=self.combobox_callback)
combobox.set("1 Week")
combobox.pack(padx=20, pady=25)
def combobox_callback(self, choice):
self.period = choice
def button_callbck(self):
fig = MPLGraph()
root = tk.Tk()
graph_page = GraphPage(root, self.period)
graph_page.add_mpl_figure(fig)
root.mainloop()
app = App()
app.mainloop()