CustomTkinter icon indicating copy to clipboard operation
CustomTkinter copied to clipboard

Error when using tk.PhotoImage on Button

Open alejandroautalan opened this issue 1 year ago • 4 comments

Hello, I have an error when using tk.PhotoImage on Button.

customtkinter version: 5.0.2

Example:

#!/usr/bin/python3
import tkinter as tk
from customtkinter import (CTk, CTkButton, CTkFrame)


class CtkButtonImageApp:
    def __init__(self, master=None):
        # build ui
        ctk1 = CTk(master)
        ctk1.geometry("320x200")
        ctkframe1 = CTkFrame(ctk1)
        ctkbutton1 = CTkButton(ctkframe1)
        self.img_135search = tk.PhotoImage(file="135-search.png")
        ctkbutton1.configure(image=self.img_135search, text='Search')
        ctkbutton1.pack(side="top")
        ctkframe1.pack(expand="true", side="top")

        # Main widget
        self.mainwindow = ctk1

    def run(self):
        self.mainwindow.mainloop()


if __name__ == "__main__":
    app = CtkButtonImageApp()
    app.run()

Error:

AttributeError: 'PhotoImage' object has no attribute 'create_scaled_photo_image'

Trace:

fades -r reqdev-ctk-v5.txt ctk_button_image_app.py 
CTkButton Warning: Given image is not CTkImage but <class 'tkinter.PhotoImage'>. Image can not be scaled on HighDPI displays, use CTkImage instead.
Traceback (most recent call last):
  File "/home/alejandro/Privado/projects/pygubu-project/issues/designer/ctk_button_image_app.py", line 26, in <module>
    app = CtkButtonImageApp()
  File "/home/alejandro/Privado/projects/pygubu-project/issues/designer/ctk_button_image_app.py", line 14, in __init__
    ctkbutton1.configure(image=self.img_135search, text='Search')
  File "/home/alejandro/.local/share/fades/43aaa717-a9e8-4062-a3da-40e427b75a69/lib/python3.10/site-packages/customtkinter/windows/widgets/ctk_button.py", line 419, in configure
    super().configure(require_redraw=require_redraw, **kwargs)
  File "/home/alejandro/.local/share/fades/43aaa717-a9e8-4062-a3da-40e427b75a69/lib/python3.10/site-packages/customtkinter/windows/widgets/core_widget_classes/ctk_base_class.py", line 138, in configure
    self._draw()
  File "/home/alejandro/.local/share/fades/43aaa717-a9e8-4062-a3da-40e427b75a69/lib/python3.10/site-packages/customtkinter/windows/widgets/ctk_button.py", line 243, in _draw
    self._update_image()  # set image
  File "/home/alejandro/.local/share/fades/43aaa717-a9e8-4062-a3da-40e427b75a69/lib/python3.10/site-packages/customtkinter/windows/widgets/ctk_button.py", line 154, in _update_image
    self._image_label.configure(image=self._image.create_scaled_photo_image(self._get_widget_scaling(),
AttributeError: 'PhotoImage' object has no attribute 'create_scaled_photo_image'

alejandroautalan avatar Dec 07 '22 04:12 alejandroautalan