def enter_pressed(text_widget):
    """Handle indentation when pressing enter."""
    current_line = text_widget.get("insert linestart", "insert lineend")
    preceding_spaces = 0

    for character in current_line:
        if character == " ":
            preceding_spaces += 1
        else:
            break
    text_widget.insert("insert lineend", "\n" + " " * preceding_spaces)
    return "break"