Coding Tutorials Hub

Learn coding with simple code, clear explanations, and examples

Python TKinter GUI - Text Widget [textbox] add/delete text

📄 Code


import tkinter as tk

def add_text():
    textbox.insert("1.0", "Welcome!")

def delete_text():
    textbox.delete("1.0", tk.END)

# Create the main window
root = tk.Tk()
root.title("Tkinter-GUI textbox Tutorial")
root.geometry("300x150")

# Create a multi-line input textbox
textbox = tk.Text(root, height=2, width=30)
textbox.pack(pady=10)

# Create a button
add_button = tk.Button(root, text="Click to add text", command=add_text)
add_button.pack(pady=5)

# Create a button
delete_button = tk.Button(root, text="Click to delete text", command=delete_text)
delete_button.pack(pady=5)

# Run the application
root.mainloop()
        
💡 Output