|
| 1 | +import tkinter as tk |
| 2 | + |
| 3 | + |
| 4 | +class OneRepMaxCalculator: |
| 5 | + """ |
| 6 | + A class used to calculate the estimated one-repetition maximum (1RM) for a weightlifting exercise. |
| 7 | +
|
| 8 | + Attributes |
| 9 | + ---------- |
| 10 | + window : tk.Tk |
| 11 | + The main window of the application. |
| 12 | + weight_entry : tk.Entry |
| 13 | + Entry field to input the weight lifted. |
| 14 | + rep_entry : tk.Entry |
| 15 | + Entry field to input the number of reps performed. |
| 16 | + result_value_label : tk.Label |
| 17 | + Label to display the calculated 1RM. |
| 18 | +
|
| 19 | + Methods |
| 20 | + ------- |
| 21 | + calculate_1rm(): |
| 22 | + Calculates the estimated 1RM based on the Epley formula. |
| 23 | + display_result(): |
| 24 | + Displays the calculated 1RM in the application window. |
| 25 | + run(): |
| 26 | + Runs the application. |
| 27 | + """ |
| 28 | + |
| 29 | + def __init__(self): |
| 30 | + """Initializes the OneRepMaxCalculator with a window and widgets.""" |
| 31 | + self.window = tk.Tk() |
| 32 | + self.window.title("One-Rep Max Calculator") |
| 33 | + self.window.geometry("300x150") |
| 34 | + |
| 35 | + # Create and pack widgets |
| 36 | + tk.Label(self.window, text="Enter the weight you lifted (in kg):").pack() |
| 37 | + self.weight_entry = tk.Entry(self.window) |
| 38 | + self.weight_entry.pack() |
| 39 | + |
| 40 | + tk.Label(self.window, text="Enter the number of reps you performed:").pack() |
| 41 | + self.rep_entry = tk.Entry(self.window) |
| 42 | + self.rep_entry.pack() |
| 43 | + |
| 44 | + tk.Button(self.window, text="Calculate", command=self.display_result).pack() |
| 45 | + |
| 46 | + tk.Label(self.window, text="Your estimated one-rep max (1RM):").pack() |
| 47 | + self.result_value_label = tk.Label(self.window) |
| 48 | + self.result_value_label.pack() |
| 49 | + |
| 50 | + def calculate_1rm(self): |
| 51 | + """Calculates and returns the estimated 1RM.""" |
| 52 | + weight = int(self.weight_entry.get()) |
| 53 | + reps = int(self.rep_entry.get()) |
| 54 | + return (weight * reps * 0.0333) + weight |
| 55 | + |
| 56 | + def display_result(self): |
| 57 | + """Calculates the 1RM and updates result_value_label with it.""" |
| 58 | + one_rep_max = self.calculate_1rm() |
| 59 | + self.result_value_label.config(text=f"{one_rep_max} kg") |
| 60 | + |
| 61 | + def run(self): |
| 62 | + """Runs the Tkinter event loop.""" |
| 63 | + self.window.mainloop() |
| 64 | + |
| 65 | + |
| 66 | +# Usage |
| 67 | +if __name__ == "__main__": |
| 68 | + calculator = OneRepMaxCalculator() |
| 69 | + calculator.run() |
| 70 | + |
| 71 | +# Improve the program. |
| 72 | +# Make the fonts, bigger. |
| 73 | +# - Use text formatting... |
| 74 | +# Use dark mode. |
| 75 | +# Have an option to use dark mode and light mode. |
0 commit comments