About Lesson
Develop a Small Application Incorporating the Concepts Learned
- Objective: Develop a small application that incorporates the concepts learned throughout the course. This project will help reinforce the knowledge and skills acquired.
- Examples:
- To-Do List Application:
- Features: Add, remove, and display tasks.
- Concepts: Lists, functions, file I/O, GUI programming.
python
import tkinter as tk tasks = [] def add_task(): task = entry.get() if task: tasks.append(task) listbox.insert(tk.END, task) entry.delete(0, tk.END) def remove_task(): selected_task_index = listbox.curselection() if selected_task_index: tasks.pop(selected_task_index[0]) listbox.delete(selected_task_index) root = tk.Tk() root.title("To-Do List") entry = tk.Entry(root) entry.pack() add_button = tk.Button(root, text="Add Task", command=add_task) add_button.pack() remove_button = tk.Button(root, text="Remove Task", command=remove_task) remove_button.pack() listbox = tk.Listbox(root) listbox.pack() root.mainloop()
- Simple Calculator:
- Features: Basic arithmetic operations (addition, subtraction, multiplication, division).
- Concepts: Functions, GUI programming.
python
import tkinter as tk def calculate(operation): try: result = eval(entry.get()) entry.delete(0, tk.END) entry.insert(tk.END, str(result)) except Exception as e: entry.delete(0, tk.END) entry.insert(tk.END, "Error") root = tk.Tk() root.title("Simple Calculator") entry = tk.Entry(root) entry.pack() buttons = [ ('7', 1, 0), ('8', 1, 1), ('9', 1, 2), ('4', 2, 0), ('5', 2, 1), ('6', 2, 2), ('1', 3, 0), ('2', 3, 1), ('3', 3, 2), ('0', 4, 1), ('+', 1, 3), ('-', 2, 3), ('*', 3, 3), ('/', 4, 3), ('=', 4, 2), ] for (text, row, col) in buttons: button = tk.Button(root, text=text, command=lambda t=text: entry.insert(tk.END, t) if t != '=' else calculate(entry.get())) button.grid(row=row, column=col) root.mainloop()
- To-Do List Application: