import tkinter as tk
from PIL import Image, ImageTk, ImageEnhance
import pygame, pyautogui
pygame.init()
# Initialize the main window
window = tk.Tk()
window.geometry("776x582")
window.resizable(0, 0)
window.config(cursor="@NORMAL.cur")
#canvas
canvas = tk.Canvas(window, width=776, height=582)
canvas.place(x=0, y=0, anchor=tk.NW)
background_image = tk.PhotoImage(file="bg.png")
canvas.create_image(0, 0, image=background_image, anchor=tk.NW, tags="background")
img1 = Image.open("char1.png").convert("RGBA")
img2 = Image.open("char2.png").convert("RGBA")
char1_img = ImageTk.PhotoImage(img1)
char2_img = ImageTk.PhotoImage(img2)
char1 = canvas.create_image(176, 250,image=char1_img,anchor=tk.NW)
char2 = canvas.create_image(200, 200,image=char2_img,anchor=tk.NW)
def brightness(image,val):
return ImageEnhance.Brightness(image).enhance(val)
def character(canv,char_x, char_y, char_w, char_h,img,char_img,char):
#character
img = brightness(img,1)
canv.itemconfig(char,image=char_img)
def motion(event,img):
x, y = event.x, event.y
if char_x < x < char_x + char_w and char_y < y < char_y + char_h:
img = brightness(img,1.3)
char_img = ImageTk.PhotoImage(img)
else:
img = brightness(img,1)
char_img = ImageTk.PhotoImage(img)
canv.itemconfig(char, image=char_img)
canv.bind('<Motion>', lambda event:motion(event,img))
#characters
character(canvas,176, 250, 103, 213,img1,char1_img,char1)
window.mainloop()
I wanted to change the img’s brightness if the mouse entered to it but when i change it the img is not updating idk why, i tried to use to use .itemconfig(and asign the bright image there), i hope you guys help me out.