Introduction

Basic Widgets

Toplevel Widgets

Geometry Management

Binding Functions

Working with Images in Tkinter

Tkinter Advance

Applications and Projects

ToDo GUI Application using Tkinter

Let's create a basic To-Do application using Tkinter. This application will allow users to:

  1. Add new tasks.
  2. Delete completed tasks.
  3. Display the list of tasks.

To-Do Application

1. Initial Setup:

import tkinter as tk
from tkinter import messagebox

# Initialize the main window
root = tk.Tk()
root.title("To-Do App")
root.geometry("300x400")

2. Define the Functions:

# Function to add a task
def add_task():
    task = task_entry.get()
    if task != "":
        tasks_listbox.insert(tk.END, task)
        task_entry.delete(0, tk.END)
    else:
        messagebox.showwarning("Warning", "Please enter a task!")

# Function to delete a task
def delete_task():
    try:
        selected_task_index = tasks_listbox.curselection()[0]
        tasks_listbox.delete(selected_task_index)
    except IndexError:
        messagebox.showwarning("Warning", "Please select a task to delete!")

3. Create Widgets:

Entry and Buttons:

frame = tk.Frame(root)
frame.pack(pady=20)

task_entry = tk.Entry(frame, width=25)
task_entry.pack(side=tk.LEFT, padx=20)

add_btn = tk.Button(frame, text="Add Task", command=add_task)
add_btn.pack(fill=tk.BOTH)

delete_btn = tk.Button(root, text="Delete Task", command=delete_task)
delete_btn.pack(pady=20)

Listbox to display tasks:

tasks_listbox = tk.Listbox(root, width=50, height=10)
tasks_listbox.pack(pady=20)

4. Main Loop:

root.mainloop()

When you put all these together and run the script, you'll have a simple To-Do GUI application using Tkinter. You can enter tasks, add them to the list, and delete them once completed.

This is a basic implementation. You can expand upon it by:

  1. Saving tasks to a file or database.
  2. Incorporating a 'mark as complete' feature, rather than deleting tasks.
  3. Adding due dates, priority levels, or task categories.
  4. Implementing a search or sort functionality.
  5. Enhancing the UI/UX with more advanced widgets or custom styling.

Remember, this is a foundational step. Once you understand these basics, you can explore more advanced features and functionalities to build a more robust To-Do application.

    import tkinter as tk
    
    def add_task():
        task = entry.get()
        if task:
            listbox.insert(tk.END, task)
            entry.delete(0, tk.END)
    
    def remove_task():
        selected_task_index = listbox.curselection()
        if selected_task_index:
            listbox.delete(selected_task_index)
    
    # Create main window
    root = tk.Tk()
    root.title("ToDo List")
    
    # Entry widget for task input
    entry = tk.Entry(root, width=30)
    entry.grid(row=0, column=0, padx=10, pady=10)
    
    # Add and Remove buttons
    add_button = tk.Button(root, text="Add Task", command=add_task)
    add_button.grid(row=0, column=1, padx=5, pady=10)
    
    remove_button = tk.Button(root, text="Remove Task", command=remove_task)
    remove_button.grid(row=0, column=2, padx=5, pady=10)
    
    # Listbox to display tasks
    listbox = tk.Listbox(root, selectmode=tk.SINGLE, width=40, height=10)
    listbox.grid(row=1, column=0, columnspan=3, padx=10, pady=10)
    
    # Start the Tkinter event loop
    root.mainloop()
    

      This example is similar to the previous one.

        import tkinter as tk
        
        def add_task():
            task = entry.get()
            if task:
                listbox.insert(tk.END, task)
                entry.delete(0, tk.END)
        
        def remove_task():
            selected_task_index = listbox.curselection()
            if selected_task_index:
                listbox.delete(selected_task_index)
        
        # Create main window
        root = tk.Tk()
        root.title("ToDo List")
        
        # Entry widget for task input
        entry = tk.Entry(root, width=30)
        entry.grid(row=0, column=0, padx=10, pady=10)
        
        # Add and Remove buttons
        add_button = tk.Button(root, text="Add Task", command=add_task)
        add_button.grid(row=0, column=1, padx=5, pady=10)
        
        remove_button = tk.Button(root, text="Remove Task", command=remove_task)
        remove_button.grid(row=0, column=2, padx=5, pady=10)
        
        # Listbox to display tasks with checkboxes
        listbox = tk.Listbox(root, selectmode=tk.SINGLE, width=40, height=10)
        listbox.grid(row=1, column=0, columnspan=3, padx=10, pady=10)
        
        # Add checkboxes to each task
        for i in range(5):
            listbox.insert(tk.END, f"Task {i+1}")
        
        # Start the Tkinter event loop
        root.mainloop()
        

          The first example covers this.

            The first example covers this.

              This involves adding update and delete functionalities to tasks, which can be achieved by extending the code. You would need to add an "Update" button and modify the code accordingly.

                The first example covers this.

                  The first example is a simple project example.