0% found this document useful (0 votes)
38 views10 pages

Import Tkinter As TK

cs project bro do your own
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views10 pages

Import Tkinter As TK

cs project bro do your own
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

import tkinter as tk

from tkinter import messagebox, ttk

import time

import threading

import mysql.connector

def init_db():

conn = mysql.connector.connect(

host="localhost",

user="root",

password="12345678",

database="study_planner"

cursor = conn.cursor()

cursor.execute('''CREATE TABLE IF NOT EXISTS timetable (

id INT AUTO_INCREMENT PRIMARY KEY,

day VARCHAR(255),

subject VARCHAR(255),

start_time VARCHAR(255),

end_time VARCHAR(255))''')

cursor.execute('''CREATE TABLE IF NOT EXISTS todo (


id INT AUTO_INCREMENT PRIMARY KEY,

task VARCHAR(255),

status VARCHAR(255))''')

conn.commit()

conn.close()

def add_timetable(day, subject, start_time, end_time):

conn = mysql.connector.connect(

host="localhost",

user="root",

password="12345678",

database="study_planner"

cursor = conn.cursor()

cursor.execute("INSERT INTO timetable (day, subject, start_time,

end_time) VALUES (%s, %s, %s,

%s)", (day, subject, start_time, end_time))

conn.commit()

conn.close()

def view_timetable():
conn = mysql.connector.connect(

host="localhost",

user="root",

password="dharshene",

database="study_planner"

cursor = conn.cursor()

cursor.execute("SELECT * FROM timetable")

rows = cursor.fetchall()

conn.close()

return rows

def add_task(task):

conn = mysql.connector.connect(

host="localhost",

user="root",

password="12345678",

database="study_planner"

cursor = conn.cursor()

cursor.execute("INSERT INTO todo (task, status) VALUES (%s, %s)",


(task, 'Pending'))
conn.commit()

conn.close()

def mark_task_done(task_id):

conn = mysql.connector.connect(

host="localhost",

user="root",

password="12345678",

database="study_planner"

cursor = conn.cursor()

cursor.execute("UPDATE todo SET status = 'Done' WHERE id = %s",

(task_id,))

conn.commit()

conn.close()

class PomodoroTimer:

def __init__(self, root):

self.root = root

self.root.title("Pomodoro Timer")

# Create the timer label


self.timer_label = tk.Label(root, text="Pomodoro Timer",

font=("Helvetica", 16))

self.timer_label.pack(pady=10)

# Initial time for Pomodoro (25 minutes = 1500 seconds)

self.time_left = 25 * 60 # 25 minutes

self.timer_running = False

# Create the timer display

self.timer_text = tk.Label(root,
text=self.format_time(self.time_left), font=("Helvetica", 24))

self.timer_text.pack(pady=10)

# Start and Stop buttons

self.start_button = tk.Button(root, text="Start Timer",


command=self.start_timer)

self.start_button.pack(side=tk.LEFT, padx=20)

self.stop_button = tk.Button(root, text="Stop Timer",


command=self.stop_timer)

self.stop_button.pack(side=tk.RIGHT, padx=20)

self.update_timer()
def format_time(self, seconds):

mins = seconds // 60

secs = seconds % 60

return f"{mins:02d}:{secs:02d}"

def update_timer(self):

# Update the timer display every second

if self.timer_running and self.time_left > 0:

self.time_left -= 1

self.timer_text.config(text=self.format_time(self.time_left))

elif self.timer_running and self.time_left == 0:

self.timer_running = False

messagebox.showinfo("Pomodoro Timer", "Time's up! Take a


break.")

# Re-run the update_timer function every 1000ms (1 second)

self.root.after(1000, self.update_timer)

def start_timer(self):

if not self.timer_running:

self.timer_running = True
if self.time_left == 0: # Reset the timer if it was stopped at 0

self.time_left = 25 * 60

def stop_timer(self):

if self.timer_running:

self.timer_running = False

def timetable_menu():

while True:

print("\n--- Timetable Menu ---")

print("1. Add a subject to the timetable")

print("2. View timetable")

print("3. Go back to main menu")

choice = input("Enter your choice: ")

if choice == '1':

day = input("Enter the day: ")

subject = input("Enter the subject: ")

start_time = input("Enter the start time (HH:MM): ")

end_time = input("Enter the end time (HH:MM): ")

add_timetable(day, subject, start_time, end_time)


print("Subject added to timetable!")

elif choice == '2':

rows = view_timetable()

print("\n--- Timetable ---")

for row in rows:

print(f"ID: {row[0]}, Day: {row[1]}, Subject: {row[2]}, Start:


{row[3]}, End: {row[4]}")

elif choice == '3':

break

else:

print("Invalid choice, please try again.")

def todo_menu():

while True:

print("\n--- To-Do List Menu ---")

print("1. Add a task")

print("2. Mark task as done")

print("3. View tasks")

print("4. Go back to main menu")

choice = input("Enter your choice: ")

if choice == '1':
task = input("Enter the task: ")

add_task(task)

print("Task added to To-Do list!")

elif choice == '2':

task_id = input("Enter the task ID to mark as done: ")

mark_task_done(task_id)

print("Task marked as done!")

elif choice == '3':

rows = view_timetable() # You should probably have a


function to view tasks

print("\n--- To-Do List ---")

for row in rows:

print(f"ID: {row[0]}, Task: {row[1]}, Status: {row[2]}")

elif choice == '4':

break

else:

print("Invalid choice, please try again.")

def main_menu():

while True:

print("\n--- Study Planner Main Menu ---")

print("1. Timetable Menu")


print("2. To-Do List Menu")

print("3. Pomodoro Timer")

print("4. Exit")

choice = input("Enter your choice: ")

if choice == '1':

timetable_menu()

elif choice == '2':

todo_menu()

elif choice == '3':

root = tk.Tk()

pomodoro_timer = PomodoroTimer(root)

root.mainloop()

elif choice == '4':

print("Exiting program. Have a productive day!")

break

else:

print("Invalid choice, please try again.")

if __name__ == "__main__":

init_db()

main_menu()

You might also like