Skip to content

In Python 3.13 REPL, print() adds extra indentation when invoked from a tkinter event handler #135045

Open
@culler

Description

@culler

Bug report

Bug description:

Here is an interactive python 3.13 session on macOS 15.5 using the python.org distribution:

Python 3.13.3 (v3.13.3:6280bb54784, Apr  8 2025, 10:47:54) [Clang 15.0.0 (clang-1500.3.9.4)] on d\
arwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tkinter
>>> interp = tkinter.Tk()
>>> f = tkinter.Frame(interp, background='blue', width=30, height=30)
>>> f.pack(padx=30, pady=30)
>>> def handler(event):
...     print("Click")
...
>>> f.bind('<Button-1>', handler)
'4384102400handler'
>>> # Now click the mouse on the blue square a few times.
>>> Click
         Click
              Click
                   Click
                        Click

The words "Click" should not be indented. No spaces are being printed. The REPL behaves as if the text is ended with a newline but not with the implicit carriage return.

I expect the print command to behave the same way as it does here:

>>> for i in range(5): print("Click")
... 
Click
Click
Click
Click
Click

CPython versions tested on:

3.13

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixestopic-replRelated to the interactive shelltopic-tkintertype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions