1

I have a GUI made with TKinter in Python and a canvas that come up when hovering on it but the problem is that when i hover many times in a short period on the canvas ,it will disappear . So, i want it to be more proffesionel

code :

from sys import argv
from tkinter import *
from PIL import ImageTk

a = -0.135
b = 0.405

ankd = 0

def doit1():
   can.bind("<Enter>", on_enter65)
   can.bind("<Leave>", on_leave65)
   can["width"] = "200"


def on_enter65(mnm):
    can["width"] = "380"
    for x in range(82):
        global ankd
        ankd += 1
        if ankd <= 82:
            can.move(1, 2, 0)
            can.update()
            can.after(1)

def on_leave65(mnm):
    win.after(250, doit1)
    for x in range(82):
        global ankd
        ankd -= 1
        if ankd >= 0:
           can.move(1, -2, 0)
           can.update()
           can.after(1)



win = Tk()   
filename = 'file.png'   
win.geometry("1230x900")
img = PhotoImage(file=filename)
can = Canvas(win,width="200",height="350")
can.pack() 
can.place(relx=a, rely=b, anchor=NW)
can.bind("<Enter>", on_enter65)
can.bind("<Leave>", on_leave65)
i = can.create_image(2, 2, image=img, anchor=NW)


win.mainloop()
Mahdi
  • 11
  • 2

0 Answers0