merhabalar, başlıkta belirtmiş oldugum gibi elimde png bir fotograf var üzerine geldigimde fotografın
renginin kırmızı olmasını istiyorum bunu kodlarla saglamak mümkünmü extra resim kullanmadan bilgilendirirseniz sevinirim.
KOD:
from functools import partial
from tkinter import*
class hover_event():
def enter_hover(widget, event):
#Renk degiştirmesini istedigim bölüm!
print("test")
def leave_hover(widget, event):
global res
print("test")
root = Tk()
root.geometry("850x750+500+200")
res1 = PhotoImage(file="../İmage/chat.png").subsample(2, 2)
label = Label(root,image=res1)
label.pack()
label.bind("<Enter>", partial(hover_event.enter_hover, label))
root.mainloop()
Yukarıdaki kodlara göre, farenin sol tuşuna basarsanız renk değişir, sağ tuşuna basarsanız, resmin rengi tekrar eski haline döner. Tabi siz bind metodunun sequence parametresini <Enter> olarak değiştirirsiniz. Bu örnekte fare düğmelerini kullandım ben.
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:/Users/user/Desktop/Python/test2.py", line 26, in <lambda>
lambda event: on_button_press(label, img, colorize=True)
File "C:/Users/user/Desktop/Python/test2.py", line 11, in on_button_press
img = ImageOps.colorize(img, black=label["bg"], white="rgb(100%, 0%, 0%)")
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\PIL\ImageOps.py", line 172, in colorize
black = _color(black, "RGB")
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\PIL\ImageOps.py", line 44, in _color
color = ImageColor.getcolor(color, mode)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\PIL\ImageColor.py", line 131, in getcolor
color, alpha = getrgb(color), 255
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\PIL\ImageColor.py", line 116, in getrgb
raise ValueError("unknown color specifier: %r" % color)
ValueError: unknown color specifier: 'systembuttonface'