Bonjour,

Ci-dessous l'exemple simple en question :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 
 
from tkinter import *
from time import *
var = 30
 
path = "C:\\XX\\XY\\XXY\\Y\\"
 
def change_img():
    tab_img = [f"{path}image1.gif",f"{path}image2.gif"] # images en 90x90
    for i in tab_img:
        photo = PhotoImage(file = i)
        canvas_logo.create_image(wi/2, he/2 ,image=photo)  
        canvas_logo.itemconfigure('image', image=photo)
        canvas_logo.update()
        sleep(1)
    win.after(1000, change_img)
 
 
win = Tk()
 
 
win.geometry("1000x720")
win.config(background='#7720B9')
 
 
 
 
def ajout_():
    global var
    canvas1 = Canvas(win, width= 200, height= 50)
    canvas1.create_rectangle(0, 0, 200, 50, fill="red")
 
 
    canvas2 = Canvas(win, width= 200, height= 50)
    canvas2.create_rectangle(0, 0, 200, 50, fill="yellow")
    canvas1.place(x=0, y=var)
    canvas2.place(x=200, y=var)
 
    myentry1 = Entry(canvas1, bd = 3)
    myentry1.place(x = 5, y = 12.5)
    myentry2 = Entry(canvas2, bd = 3)
    myentry2.place(x = 5, y = 12.5)
 
    var = var + 50
 
wi = 90
he  = 90
canvas_logo = Canvas(win, width= wi, height= he)
photo = PhotoImage(file=f"{path}image1.gif")
canvas_logo.create_image(wi/2, he/2 ,image=photo)
canvas_logo.place(x=600, y=0)
 
bu_ajout = Button(win, text = "Ajout", command = ajout_)
bu_ajout.place(x = 0, y = 0)
 
 
win.after(1000, change_img)
 
 
win.mainloop()
Ce qui se passe c'est que lorsque j'appuie sur le bouton Ajout le progr. fait bien ce que je souhaite mais freeze un peu l'application pendant que les images changent dans le canvas. Y'aurait-il un moyen d'éviter cela?

PS: j'ai essayé de mettre la fonction chang_img en tant que threading mais j'ai toujours le même problème.

Donc si quelqu'un a déjà rencontré ce problème je veux bien un petit coup de pouce. Merci.