Bonjour, mon programme permet de savoir si le ventilateur de mon raspberry est activé ou non dans une fenêtre tkinter, voici mon programme:

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
#!/usr/bin/python3
from tkinter import *
from time import sleep
from PIL import ImageTk
from PIL import Image
import tkinter as Fan
 
root = Tk()
root.geometry('150x50+1500+50')
root.title('Fan2')
var = StringVar()
image1 = Image.open('ventilo.png')
Fan_image1 = ImageTk.PhotoImage(image1)
image2 = Image.open('non_ventilo.png')
Fan_image2 = ImageTk.PhotoImage(image2)
with open('/sys/class/thermal/cooling_device0/cur_state', 'r') as fan:
#with open('/home/pi/Desktop/test', 'r') as fan:    
    gfan = int(fan.read())
var.set('ventilateur')
l = Label(root, textvariable = var, image=Fan_image1, compound='left')
l.pack()
while True:
    #with open('/home/pi/Desktop/test', 'r') as fan:
    with open('/sys/class/thermal/cooling_device0/cur_state', 'r') as fan:
        gfan = int(fan.read())
    #for i in range(6):
        sleep(1) # Need this to slow the changes down
        var.set('  désactivé' if gfan==0 else '  activé')
        root.update_idletasks()
Je cherche à faire la même chose mais en changeant une image, si il est activé une image, si il est désactivé une autre image, avec mise à jour instantanée. Je n'arrive pas à savoir comment faire.

Si quelqu'un à une idée?

Merci