This repository was archived by the owner on Aug 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweight-tracker-02.py
More file actions
75 lines (53 loc) · 1.8 KB
/
weight-tracker-02.py
File metadata and controls
75 lines (53 loc) · 1.8 KB
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
## pip install matplotlib
## sudo apt install python3-pil.imagetk
##---------------------------------------------------------------------------##
# IMPORTS
from tkinter import *
from tkinter import simpledialog
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg as TkCanvas
##---------------------------------------------------------------------------##
# CONSTANTS
BACK_COLOR = "#1e1e1e"
FORE_COLOR = "#fefefe"
##---------------------------------------------------------------------------##
# MUTABLES
weights = [78, 77, 78, 75, 73, 70]
##---------------------------------------------------------------------------##
# CONFIGURATIONS
plt.style.use("dark_background")
##---------------------------------------------------------------------------##
# Functions
def add():
weights.append(simpledialog.askfloat("New Weight", "Enter your new weight"))
clear()
plot()
canvas: TkCanvas = None
figure: plt.Figure = None
def plot():
global canvas, figure
figure = plt.Figure(dpi=100)
canvas = TkCanvas(figure, window)
canvas.get_tk_widget().pack(fill="both", expand=True)
ax = figure.add_subplot()
ax.plot(["Week " + str(x) for x in range(len(weights))], weights)
canvas.draw()
def clear():
global canvas, figure
canvas.get_tk_widget().pack_forget()
#del canvas
del figure
##---------------------------------------------------------------------------##
# APPLICATION
window = Tk()
window.geometry("600x400")
window.title("Weekly Weight App")
window.config(background=BACK_COLOR)
btn = Button(window, text="Add new weight", command=add)
btn.config(background=BACK_COLOR)
btn.config(foreground=FORE_COLOR)
btn.pack()
plot()
##---------------------------------------------------------------------------##
# MAIN LOOP
window.mainloop()