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() |