0% found this document useful (0 votes)
9 views

PDF of Py Project

Uploaded by

HATIM Ali Bohra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

PDF of Py Project

Uploaded by

HATIM Ali Bohra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

import tkinter as tk

from tkinter import ttk, messagebox


import sqlite3

class FitnessTrackerApp:
def __init__(self, root):
self.root = root
self.root.title("Fitness Tracker")
self.root.geometry("800x600")
self.root.configure(bg="#f0f0f0")

# Set up styles
self.style = ttk.Style()
self.style.configure("TNotebook", background="#f0f0f0")
self.style.configure("TNotebook.Tab", background="#d9d9d9", padding=[10, 5])
self.style.map("TNotebook.Tab", background=[("selected", "#a6a6a6")])
self.style.configure("TButton", background="#4CAF50", foreground="white", font=("Arial", 12))
self.style.map("TButton", background=[("active", "#45a049")])

# Create a notebook for multiple tabs


self.notebook = ttk.Notebook(self.root)
self.notebook.pack(pady=10, expand=True)

# Create tabs for login, registration, workout tracking, and progress monitoring
self.login_tab = ttk.Frame(self.notebook)
self.registration_tab = ttk.Frame(self.notebook)
self.workout_tab = ttk.Frame(self.notebook)
self.progress_tab = ttk.Frame(self.notebook)
self.notebook.add(self.login_tab, text="Login")
self.notebook.add(self.registration_tab, text="Register")
self.notebook.add(self.workout_tab, text="Workout Tracking")
self.notebook.add(self.progress_tab, text="Progress Monitoring")

# Initialize database
self.init_db()

# Create UI components
self.create_login_tab()
self.create_registration_tab()
self.create_workout_tab()
self.create_progress_tab()

def init_db(self):
"""Initialize the database and create tables if they do not exist."""
try:
conn = sqlite3.connect("fitness_tracker.db")
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
username TEXT UNIQUE,
password TEXT
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS workouts (
id INTEGER PRIMARY KEY,
workout_type TEXT,
duration INTEGER,
calories INTEGER
)
''')
conn.commit()
except sqlite3.Error as e:
messagebox.showerror("Database Error", f"An error occurred: {e}")
finally:
conn.close()

def create_login_tab(self):
"""Create the login tab UI components."""
ttk.Label(self.login_tab, text="Username:", font=("Arial", 14)).pack(pady=10)
self.login_entry = ttk.Entry(self.login_tab, font=("Arial", 12))
self.login_entry.pack(pady=10)

ttk.Label(self.login_tab, text="Password:", font=("Arial", 14)).pack(pady=10)


self.password_entry = ttk.Entry(self.login_tab, show="*", font=("Arial", 12))
self.password_entry.pack(pady=10)

ttk.Button(self.login_tab, text="Login", command=self.login).pack(pady=20)

def create_registration_tab(self):
"""Create the registration tab UI components."""
ttk.Label(self.registration_tab, text="Username:", font=("Arial", 14)).pack(pady=10)
self.reg_username_entry = ttk.Entry(self.registration_tab, font=("Arial", 12))
self.reg_username_entry.pack(pady=10)
ttk.Label(self.registration_tab, text="Password:", font=("Arial", 14)).pack(pady=10)
self.reg_password_entry = ttk.Entry(self.registration_tab, show="*", font=("Arial", 12))

You might also like