How to copy the contents of the clipboard into a window

2025-12-25 Thursday 8h 49 pm Merry Christmas to all! This piece of code can be very useful

proc copy.clipboard.contents.in.window {} {
    # Get clipboard content
    set clipboard_content [clipboard get]

    # Check if clipboard content is empty
    if {[string length $clipboard_content] == 0} {
        set clipboard_content "Clipboard is empty."
    }

    # Create a new toplevel window
    toplevel .top

    # Set the background color to yellow using the window manager (wm)
    .top configure -background yellow

    # Set the content in the window as the clipboard content
    label .top.lbl -text $clipboard_content -background yellow
    pack .top.lbl

    # Ensure the window is visible and interactive
    update idletasks
}