Password Manager

 import sqlite3

import tkinter as tk

from tkinter import messagebox

from cryptography.fernet import Fernet

import random

import string

import os


# Generate and save encryption key

KEY_FILE = "key.key"


def generate_key():

    if not os.path.exists(KEY_FILE):

        key = Fernet.generate_key()

        with open(KEY_FILE, "wb") as key_file:

            key_file.write(key)


def load_key():

    with open(KEY_FILE, "rb") as key_file:

        return key_file.read()


generate_key()

key = load_key()

cipher = Fernet(key)


# Database Setup

conn = sqlite3.connect("passwords.db")

cursor = conn.cursor()

cursor.execute("""

    CREATE TABLE IF NOT EXISTS passwords (

        id INTEGER PRIMARY KEY,

        website TEXT,

        username TEXT,

        password TEXT

    )

""")

conn.commit()


# Function to encrypt password

def encrypt_password(password):

    return cipher.encrypt(password.encode()).decode()


# Function to decrypt password

def decrypt_password(encrypted_password):

    return cipher.decrypt(encrypted_password.encode()).decode()


# Function to generate a random password

def generate_password():

    characters = string.ascii_letters + string.digits + string.punctuation

    return ''.join(random.choice(characters) for _ in range(12))


# Function to save credentials

def save_password():

    website = website_entry.get()

    username = username_entry.get()

    password = password_entry.get()


    if not website or not username or not password:

        messagebox.showerror("Error", "All fields are required!")

        return


    encrypted_password = encrypt_password(password)

    cursor.execute("INSERT INTO passwords (website, username, password) VALUES (?, ?, ?)",

                   (website, username, encrypted_password))

    conn.commit()

    messagebox.showinfo("Success", "Password saved successfully!")


    website_entry.delete(0, tk.END)

    username_entry.delete(0, tk.END)

    password_entry.delete(0, tk.END)


# Function to retrieve passwords

def retrieve_passwords():

    cursor.execute("SELECT website, username, password FROM passwords")

    records = cursor.fetchall()


    result_text.delete(1.0, tk.END)

    for record in records:

        website, username, encrypted_password = record

        decrypted_password = decrypt_password(encrypted_password)

        result_text.insert(tk.END, f"Website: {website}\nUsername: {username}\nPassword: {decrypted_password}\n\n")


# Function to generate a random password

def fill_generated_password():

    password_entry.delete(0, tk.END)

    password_entry.insert(0, generate_password())


# GUI Setup

root = tk.Tk()

root.title("Password Manager")

root.geometry("400x500")


tk.Label(root, text="Website:").pack()

website_entry = tk.Entry(root, width=40)

website_entry.pack()


tk.Label(root, text="Username:").pack()

username_entry = tk.Entry(root, width=40)

username_entry.pack()


tk.Label(root, text="Password:").pack()

password_entry = tk.Entry(root, width=40, show="*")

password_entry.pack()


tk.Button(root, text="Generate Password", command=fill_generated_password).pack(pady=5)

tk.Button(root, text="Save Password", command=save_password).pack(pady=5)

tk.Button(root, text="Retrieve Passwords", command=retrieve_passwords).pack(pady=5)


result_text = tk.Text(root, height=10, width=45)

result_text.pack()


root.mainloop()


Book Tracker

 import sqlite3

from tkinter import Tk, Label, Entry, Button, ttk, messagebox


# Database setup

def setup_database():

    conn = sqlite3.connect('books.db')

    cursor = conn.cursor()

    cursor.execute("""

        CREATE TABLE IF NOT EXISTS books (

            id INTEGER PRIMARY KEY AUTOINCREMENT,

            title TEXT NOT NULL,

            author TEXT NOT NULL,

            status TEXT NOT NULL

        )

    """)

    conn.commit()

    conn.close()


# Add book

def add_book(title, author, status):

    if not title or not author or not status:

        messagebox.showerror("Error", "All fields are required.")

        return

    conn = sqlite3.connect('books.db')

    cursor = conn.cursor()

    cursor.execute("INSERT INTO books (title, author, status) VALUES (?, ?, ?)", (title, author, status))

    conn.commit()

    conn.close()

    messagebox.showinfo("Success", "Book added successfully!")

    refresh_list()


# Get books

def get_books():

    conn = sqlite3.connect('books.db')

    cursor = conn.cursor()

    cursor.execute("SELECT id, title, author, status FROM books")

    books = cursor.fetchall()

    conn.close()

    return books


# Update book status

def update_status(book_id, new_status):

    conn = sqlite3.connect('books.db')

    cursor = conn.cursor()

    cursor.execute("UPDATE books SET status = ? WHERE id = ?", (new_status, book_id))

    conn.commit()

    conn.close()

    messagebox.showinfo("Success", "Book status updated successfully!")

    refresh_list()


# Delete book

def delete_book(book_id):

    conn = sqlite3.connect('books.db')

    cursor = conn.cursor()

    cursor.execute("DELETE FROM books WHERE id = ?", (book_id,))

    conn.commit()

    conn.close()

    messagebox.showinfo("Success", "Book deleted successfully!")

    refresh_list()


# Refresh the book list in the GUI

def refresh_list():

    for row in tree.get_children():

        tree.delete(row)

    books = get_books()

    for book in books:

        tree.insert("", "end", values=book)


# GUI setup

def setup_gui():

    global tree

    root = Tk()

    root.title("Book Tracker")


    # Labels and input fields

    Label(root, text="Title:").grid(row=0, column=0, padx=5, pady=5)

    title_entry = Entry(root)

    title_entry.grid(row=0, column=1, padx=5, pady=5)


    Label(root, text="Author:").grid(row=1, column=0, padx=5, pady=5)

    author_entry = Entry(root)

    author_entry.grid(row=1, column=1, padx=5, pady=5)


    Label(root, text="Status:").grid(row=2, column=0, padx=5, pady=5)

    status_combobox = ttk.Combobox(root, values=["To Read", "Reading", "Finished"])

    status_combobox.grid(row=2, column=1, padx=5, pady=5)


    # Buttons

    Button(root, text="Add Book", command=lambda: add_book(title_entry.get(), author_entry.get(), status_combobox.get())).grid(row=3, column=0, columnspan=2, pady=10)


    # Book list

    columns = ("ID", "Title", "Author", "Status")

    tree = ttk.Treeview(root, columns=columns, show="headings")

    for col in columns:

        tree.heading(col, text=col)

        tree.column(col, width=150)

    tree.grid(row=4, column=0, columnspan=2, padx=5, pady=5)


    # Actions

    Button(root, text="Update Status", command=lambda: update_status(tree.item(tree.focus())['values'][0], status_combobox.get())).grid(row=5, column=0, pady=10)

    Button(root, text="Delete Book", command=lambda: delete_book(tree.item(tree.focus())['values'][0])).grid(row=5, column=1, pady=10)


    refresh_list()

    root.mainloop()


if __name__ == "__main__":

    setup_database()

    setup_gui()


Python is TIOBE's programming language of the year 2024!

 TIOBE Index for January 2025

January Headline: Python is TIOBE's programming language of the year 2024!

Programming language Python has won the title "TIOBE's programming language of the year 2024". This award is given to the programming language with the highest increase in ratings in one year time. Python gained a whopping 9.3% in 2024. This is far ahead of its competition: Java +2.3%, JavaScript +1.4% and Go +1.2%. Python is everywhere nowadays, and it is the undisputed default language of choice in many fields. It might even become the language with the highest ranking ever in the TIOBE index. Python's only serious drawbacks are (and thus leaving room for competition) its lack of performance and that most errors occur run-time.

For More Information   https://www.tiobe.com/tiobe-index/

Pomodoro Timer

 import tkinter as tk

from tkinter import messagebox

import time


# Constants

WORK_MIN = 25  # Work duration in minutes

SHORT_BREAK_MIN = 5  # Short break duration in minutes

LONG_BREAK_MIN = 15  # Long break duration in minutes

CYCLES = 4  # Number of work sessions before a long break


class PomodoroTimer:

    def __init__(self):

        self.root = tk.Tk()

        self.root.title("Pomodoro Timer")

        self.timer_running = False

        self.current_cycle = 0

        self.time_left = 0


        # UI Setup

        self.label = tk.Label(self.root, text="Pomodoro Timer", font=("Arial", 20))

        self.label.pack(pady=10)


        self.time_label = tk.Label(self.root, text="00:00", font=("Arial", 40))

        self.time_label.pack(pady=10)


        self.start_button = tk.Button(self.root, text="Start", font=("Arial", 15), command=self.start_timer)

        self.start_button.pack(side="left", padx=10)


        self.reset_button = tk.Button(self.root, text="Reset", font=("Arial", 15), command=self.reset_timer)

        self.reset_button.pack(side="right", padx=10)


    def start_timer(self):

        if not self.timer_running:

            self.current_cycle += 1

            if self.current_cycle % (CYCLES + 1) == 0:

                self.time_left = LONG_BREAK_MIN * 60

                self.label.config(text="Long Break", fg="blue")

            elif self.current_cycle % 2 == 0:

                self.time_left = SHORT_BREAK_MIN * 60

                self.label.config(text="Short Break", fg="green")

            else:

                self.time_left = WORK_MIN * 60

                self.label.config(text="Work", fg="red")


            self.timer_running = True

            self.countdown()


    def countdown(self):

        if self.time_left > 0:

            mins, secs = divmod(self.time_left, 60)

            self.time_label.config(text=f"{mins:02}:{secs:02}")

            self.time_left -= 1

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

        else:

            self.timer_running = False

            self.time_label.config(text="00:00")

            if self.current_cycle % 2 != 0:

                messagebox.showinfo("Time's up!", "Time for a break!")

            else:

                messagebox.showinfo("Time's up!", "Time to work!")


    def reset_timer(self):

        self.timer_running = False

        self.current_cycle = 0

        self.time_left = 0

        self.label.config(text="Pomodoro Timer", fg="black")

        self.time_label.config(text="00:00")


    def run(self):

        self.root.mainloop()


# Run the Pomodoro Timer

if __name__ == "__main__":

    PomodoroTimer().run()