Python GUI
Python GUI
>>Code:
import tkinter as tk
from tkinter import messagebox
import sqlite3
def add_exercise():
try:
duration = int(duration_entry.get())
exercise = exercise_var.get()
duration_entry.delete(0, tk.END)
except ValueError:
messagebox.showerror("Input Error", "Please Enter a Valid Duration")
def calculate_total():
cursor.execute("SELECT name, duration FROM exercises")
exercises = cursor.fetchall()
def clear_database():
cursor.execute("DELETE FROM exercises")
conn.commit()
result_label.config(text="Data cleared.")
# GUI Elements
title_label = tk.Label(t, text="-- Fitness Tracker --", font=("Helvetica", 18, "bold"))
title_label.pack(pady=20)
exercise_var = tk.StringVar()
exercise_var.set("Select Exercise")
Explanation:
calories_per_minute = {
"Running": 10, # Key: "Running", Value: 10
"Yoga": 3, # Key: "Yoga", Value: 3
"Cycling": 8 # Key: "Cycling", Value: 8
}
calories_per_minute = {
"Running": 10,
"Yoga": 3,
"Cycling": 8
}
# Fetching calories burned per minute for Running
calories_running = calories_per_minute.get("Running", 0)
print(calories_running) # Output: 10