TheLizzard · GitHub

Bug report

Bug description:

import tkinter as tk
root = tk.Tk()
print("background" in root)

Prints the following stack trace:

Traceback (most recent call last):
  File "/example.py", line 3, in <module>
    print("background" in root)
          ^^^^^^^^^^^^^^^^^^^^
  File "/tkinter/__init__.py", line 1727, in cget
    return self.tk.call(self._w, 'cget', '-' + key)
                                         ~~~~^~~~~
TypeError: can only concatenate str (not "int") to str

The TypeError referencing concatenation of an int to a str is very misleading. Error messages that don't make sense can be very confusing especially for beginners who don't know about magic methods like __iter__ and __getitem__.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Read the original on github.com ↗