New GitHub issue #110523 from Volker-Weissmann:<br>

<hr>

<pre>
# Bug report

### Bug description:

This code here:
```python
import tkinter as tk
from PIL import Image, ImageTk

class Root(tk.Tk):
    def __init__(self):
        super().__init__()

        self.frame = tk.Frame()
        self.frame.pack(expand=True)

 self.ref_count_hack = []

        for i in range(2):
            img = Image.open(open("/home/volker/Downloads/Python-logo-notext.svg.png", "rb"))
            img_width, img_height = img.size
            scale = min(300 / img_width, 300 / img_height)
            img = img.resize((round(img_width * scale), round(img_height * scale)))
 img = ImageTk.PhotoImage(img)
            if True:
 self.ref_count_hack.append(img)
            label = tk.Label(
 self.frame,
                highlightthickness=1,
                image = img
            )
            r, c = divmod(i, 2)
 label.grid(row=r, column=c)

root = Root()
root.mainloop()
```
works fine. It creates a window that looks like this:
![image](https://github.com/python/cpython/assets/39418860/e648debb-0561-49fa-ae18-cb4eb7d4e414)

But once I replace `if True:` with `if i == 1:`, the windows looks like this:
![image](https://github.com/python/cpython/assets/39418860/0c45b19a-3e70-4635-b8e0-893fbe8eeb22)


### CPython versions tested on:

3.11

### Operating systems tested on:

Linux
</pre>

<hr>

<a href="https://github.com/python/cpython/issues/110523">View on GitHub</a>
<p>Labels: type-bug</p>
<p>Assignee: </p>