Skip to content

tkinter.PhotoImage.put should accept image file content as bytes #13931

Open
@Akuli

Description

@Akuli

At runtime, this displays the image with no errors. It should type-check without errors, but it doesn't.

import tkinter

with open("my_image.png", "rb") as file:
    data = file.read()

label = tkinter.Label()
image = tkinter.PhotoImage()
image.put(data, to=(0, 0))  # This line is a mypy error
label.config(image=image)
label.pack()
tkinter.mainloop()

Mypy error is:

asd.py:8: error: Argument 1 to "put" of "PhotoImage" has incompatible type "bytes"; expected "str | list[str] | list[list[str]] | list[tuple[str, ...]] | tuple[str, ...] | tuple[list[str], ...] | tuple[tuple[str, ...], ...]"  [arg-type]

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedAn actionable problem of low to medium complexity where a PR would be very welcomestubs: false positiveType checkers report false errorstopic: tkintertkinter-related issues

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions