Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
culler opened this issue Jun 2, 2025 · 2 comments
Labels
3.13 bugs and security fixes 3.14 bugs and security fixes 3.15 new features, bugs and security fixes topic-repl Related to the interactive shell topic-tkinter type-bug An unexpected behavior, bug, or error

Comments

@culler
Copy link
Contributor

culler commented Jun 2, 2025

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

@culler culler added the type-bug An unexpected behavior, bug, or error label Jun 2, 2025
@tomasr8
Copy link
Member

tomasr8 commented Jun 2, 2025

I can reproduce this on main on Linux. Running with PYTHON_BASIC_REPL=1 , the output is not indented.

@tomasr8 tomasr8 added 3.13 bugs and security fixes 3.14 bugs and security fixes topic-repl Related to the interactive shell labels Jun 2, 2025
@ZeroIntensity ZeroIntensity added 3.15 new features, bugs and security fixes topic-tkinter labels Jun 2, 2025
@culler
Copy link
Contributor Author

culler commented Jun 3, 2025

I would like to add that this issue also causes tracebacks to be unreadable if an exception is raised within a tkinter event handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 bugs and security fixes 3.15 new features, bugs and security fixes topic-repl Related to the interactive shell topic-tkinter type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants