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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
| import bme280
from Tkinter import *
import Tkinter as tk
import time
import locale
import glob
import os
fenetre = tk.Tk()
fenetre.attributes("-fullscreen",1)
fenetre.overrideredirect(1)
fenetre.title("fun-Weather 2017 V1.0 By Alexandre Richard")
fenetre.resizable(width=False, height=False)
# canvas
canvas = tk.Canvas(fenetre, width=1022, height=598, background='black')
canvas.pack()
#définir les images de base avec photo image
#hiver
img1 = PhotoImage(file="/home/pi/Desktop/Funweather/datafunweather/hiver.gif")
#printemps
img2 = PhotoImage(file="/home/pi/Desktop/Funweather/datafunweather/printemps.gif")
#été
img3 = PhotoImage(file="/home/pi/Desktop/Funweather/datafunweather/ete.gif")
#automne
img4 = PhotoImage(file="/home/pi/Desktop/Funweather/datafunweather/automne.gif")
#fonction qui recupere la date et affiche l'image en fonction de celle-ci
def startphoto():
#on recupere la date
now = time.strftime("%m%d",time.localtime())
print now
#on affiche une des 4 immages en fonction de la date (saison)
# on envoi l'image dans le canvas
if now>="0101" and now <="0319": # hiver
#canvas.delete(ALL)
item = canvas.create_image(0,0, anchor=NW, image=img1)
if now>="0320" and now <="0620": # Printemps
#canvas.delete(ALL)
item = canvas.create_image(0,0, anchor=NW, image=img2)
if now>="0621" and now <="0921": # été
#canvas.delete(ALL)
item = canvas.create_image(0,0, anchor=NW, image=img3)
if now>="0922" and now <="1220": # automne
#canvas.delete(ALL)
item = canvas.create_image(0,0, anchor=NW, image=img4)
if now>="1221" and now <="1231": # Hiver
#canvas.delete(ALL)
item = canvas.create_image(0,0, anchor=NW, image=img1)
#Lignes dans le canvas
ligne1 = canvas.create_line(512, 0, 512, 600, fill="white")
ligne2 = canvas.create_line(0, 150, 1024, 150,fill="white")
ligne3 = canvas.create_line(0, 300, 1024, 300,fill="white")
ligne4 = canvas.create_line(512, 450, 1024, 450,fill="white")
startphoto()
## Crée un item text. Il sera ID #1
id_text1 = canvas.create_text(512, 75, text='heure', font="FreeSans 55", fill="white")
print(id_text1)
id_text2 = canvas.create_text(760, 125, text='day', font="FreeSans 25", fill="white")
print(id_text2)
# affiche l'heure courante
def majheure():
now = "12h 36min 5s " # COMPLETER AVEC L'HEURE ACTUELLE avec time
now = time.strftime(" %H:%M:%S %d-%m-%Y",time.localtime())
#L'objet now est iséré dans le canvas
canvas.itemconfig(id_text1, text=now)
#Ajout de la date en toutes lettres
#on initialise la locale du système (pour avoir la date dans la langue système)
locale.setlocale(locale.LC_ALL,'' )
#On cree la date en toutes lettres
nameday = time.strftime(" %A-%d-%B")
#puis on insère l'objet dans le canvas
canvas.itemconfig(id_text2, text=nameday)
# Commande qui rappelle la fonction majheure après 300ms
#time.sleep(0.2)
fenetre.after(1000,majheure)
fenetre.after(1000, majheure)
# Création d'un bouton pour demarrer l'horloge
##demarre = Button(fenetre, text="demarrer", command=update)
# Création d'un bouton pour quitter la station meteo, dans le cannvas
#quitte = Button(fenetre, text="quitter", command=fenetre.destroy)
bt_quit = Button(fenetre, text="Quitter", command=fenetre.destroy)
bt_quit_fenetre = canvas.create_window(987, 585, window=bt_quit)
# Affichage du label et des boutons dans la fenêtre
#label.pack()
#demarre.pack()
#bt_quit_fenetre.pack(side =TOP, padx =2, pady =2)
fenetre.mainloop() |
Partager