is it possible to find out the image assigned to the button? #2711
Unanswered
ArturDomhan
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I don't think there is any way, because the button image is not a string, but a PIL object. Unless you store the path separately, like import customtkinter as ctk
from PIL import Image
def get_image():
print(image_path)
root = ctk.CTk()
image_path = "image.png"
image = ctk.CTkImage(Image.open(image_path), size=(40, 40))
button = ctk.CTkButton(root, image=image, command=get_image)
button.pack()
root.mainloop() |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I wanted to find out which image is currently on the button, and when I used .cget('image'), I got something like:
<customtkinter.windows.widgets.image.ctk_image.CTkImage object at 0x000001BD92568A50>
Is it possible to get something more specific? After all, during the interface rendering, the image assigned via image= is definitely known.
Sometimes I need to know which image is currently on the button, and I really don’t want to just reassign it — I’d like to make a change only if the check shows a specific image.
You can see how this looks, and if everything is just constantly reassigned, it turns into a mess.
https://www.linkedin.com/posts/a-kilin_new-alarms-sounds-and-messaging-python-activity-7314755802748116992-MxEj
Beta Was this translation helpful? Give feedback.
All reactions