Python 3 Tkinter Prepopulate a Text Entry Field With Suggested or Default Text GUI Desktop App

Python 3 Tkinter Prepopulate a Text Entry Field With Suggested or Default Text GUI Desktop App

Python 3 Tkinter Prepopulate a Text Entry Field With Suggested or Default Text GUI Desktop App

import tkinter as tk

tk.Tk()

textbox = tk.Text(height=10, width=10)
textbox.insert(tk.END, "Default")
textbox.pack()

# This is for demonstration purposes
tk.Text(height=10, width=10).pack()

def default(event):
    current = textbox.get("1.0", tk.END)
    if current == "Defaultn":
        textbox.delete("1.0", tk.END)
    elif current == "n":
        textbox.insert("1.0", "Default")

textbox.bind("<FocusIn>", default)
textbox.bind("<FocusOut>", default)

tk.mainloop()
Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment