Accueil > > > HORLOGE-CHRONOMÈTRE-RÉVEIL
HORLOGE-CHRONOMÈTRE-RÉVEIL
Information sur la source
Description
Encore une horloge !.....elle est toute petite et elle permet de programmer une alarme (très utile quand vous oubliez l'heure dans votre codage python) elle permet aussi de chronométrer des évènements, mais encore, cerise sur le gâteau, elle donne l'heure !
Source
- # horloge analogique
- # -*- coding: utf_8 -*-
- from Tkinter import *
- from math import *
- from time import *
- from winsound import *
-
- global hala , mala, heuala, iala, ichro, t0, dessala, iafd
- hala, mala, heuala, iala, ichro, t0, dessala, iafd = 0, 0, 0, 0, 0, 0, 0, 0
-
- def dessine_horloge() :
- can1.create_oval(25, 25, 175, 175, fill='', width=8,outline='gold')
- can1.create_oval(20, 20, 180, 180, fill='', width=1)
- can1.create_oval(92,92,108,108, fill='gold',outline='black',width=1,tag="axe")
- can1.tag_bind("axe","<ButtonRelease>",affich_digit)
- can1.tag_bind("axe","<Enter>",curseur_main)
- can1.tag_bind("axe","<Leave>",curseur_fleche)
- i = 1
- while i < 61 :
- j = i*((2*pi)/60)
- # diametre horloge = 75 centre canvas =100,100
- x=(cos(j)*75)+100
- y=(sin(j)*75)+100
- can1.create_oval(x-1, y-1, x+1, y+1, fill='blue')
- if i in (15,30,45,60):
- can1.create_oval(x-4, y-4, x+4, y+4, fill='black')
- if i in (5,10,20,25,35,40,50,55):
- can1.create_oval(x-2, y-2, x+2, y+2, fill='blue')
- i = i+1
-
- def affich_digit(e) :
- global iafd
- if iafd == 0 :
- iafd=1
- else : iafd=0
-
- def aff_heure() :
- global hala, mala, heuala, indala, iafd
- dateheure=localtime()
- heur=dateheure[3]
- minu=dateheure[4]
- seco=dateheure[5]
- heurd=heur
- minud=minu
- if str(heur) == str(hala) and str(minu) == str(mala) and iala == 1 :
- Beep(800,100)
- if heur >12 :
- heur = heur -12
- if ichro == 1 :
- t1=(dateheure[3]*3600)+(dateheure[4]*60)+dateheure[5]
- tchro = t1 - t0
- hchro = int(tchro/3600)
- mchro = int((tchro-(hchro*3600))/60)
- schro=tchro-(hchro*3600)-(mchro*60)
- affchro.configure(text = '%d' %hchro+'.%02d' %mchro+'.%02d'%schro, bg='white')
- # affich heures
- heur=heur+(minu/60.00)
- j=(heur+9)*((2*pi)/12)
- x=(cos(j)*55)+100
- y=(sin(j)*55)+100
- can1.coords(aigheu, 100, 100, x, y)
- # affich minutes
- minu=minu+(seco/60.0)
- j=(minu+45)*((2*pi)/60)
- x=(cos(j)*65)+100
- y=(sin(j)*65)+100
- can1.coords(aigmin, 100, 100, x, y)
- # affich secondes
- j=(seco+45)*((2*pi)/60)
- x=(cos(j)*70)+100
- y=(sin(j)*70)+100
- can1.coords(aigsec, 100, 100, x, y)
- if ichro == 1 and tchro < 60 :
- x=(cos(j)*84)+100
- y=(sin(j)*84)+100
- can1.create_oval(x-1, y-1, x+1, y+1, fill='green', outline='darkgreen')
- #afficher heure digitale
- if iafd == 1 :
- afdigi.configure(text = '%d' %heurd +" h " +'%02d' %minud)
- else : afdigi.configure(text ='',bg='lightgrey')
- can1.after(999,aff_heure)
-
- def dessine_alarme() :
- global can2 , choixala, iala, dessala
- if dessala == 0 :
- can2 = Canvas(fen1, width=200, height=50, bg='lightgrey')
- can2.pack()
- choixala = Label(can2,font=('Arial', 7),fg='darkgreen')
- choixala.pack(side=BOTTOM)
- curs= Scale(can2, from_=0.0, to=12.00, length=150, sliderlength=7,
- resolution=0.01, showvalue=0, orient=HORIZONTAL,
- label="Réglage de l'alarme :",command=choix_alarme,font=('Arial', 8),fg='blue')
- curs.pack(side=LEFT)
- bouon=Button(can2, text="On", command=set_alarme,font=('Arial', 7),bg='grey')
- bouon.pack(side=BOTTOM)
- dessala = 1
- bouoff=Button(can2, text="Off", command=setoff_alarme,font=('Arial', 7),bg='grey')
- bouoff.pack(side=BOTTOM)
-
- def choix_alarme(valcurs) :
- global hala, mala, heuala
- heuala=float(valcurs)
- j=(heuala+9)*((2*pi)/12)
- x=(cos(j)*70)+100
- y=(sin(j)*70)+100
- can1.coords(aigala, 100, 100, x, y)
- can1.itemconfigure(aigala,fill="red")
- hala=int(heuala)
- mala=int((heuala - hala) * 60)
- dateheure=localtime()
- heur=dateheure[3]
- if heur > 11 :
- hala = hala + 12
- choixala.configure(text = "Déclencher l'alarme à " +'% d' %hala +" h. " +'%02d' %mala)
-
- def set_alarme() :
- global indala, iala, dessala
- dessala = 0
- if iala ==1 :
- can1.delete(indala)
- bouala.config(bg='red')
- j=(heuala+9)*((2*pi)/12)
- x=(cos(j)*75)+100
- y=(sin(j)*75)+100
- indala=can1.create_oval(x-2, y-2, x+2, y+2, fill='red')
- iala =1
- affala.configure(text = '%d' %hala +" h." +'%02d' %mala,bg='white')
- can2.destroy()
- Beep(1000,20)
-
- def setoff_alarme() :
- global indala, iala, dessala
- if dessala == 1 :
- can2.destroy()
- dessala = 0
- bouala.config(bg='grey')
- can1.itemconfigure(aigala,fill="lightgrey")
- if iala ==1 :
- can1.delete(indala)
- iala =0
- affala.configure(text = '',bg='lightgrey')
- Beep(100,50)
-
- def chrono() :
- global ichro, t0
- if ichro == 0 :
- ichro = 1
- dateheure=localtime()
- t0=(dateheure[3]*3600)+(dateheure[4]*60)+dateheure[5]
- bouchro.config(bg='green')
- elif ichro == 1 :
- ichro = 2
- bouchro.config(bg='lightblue')
- else :
- ichro = 0
- bouchro.config(bg='grey')
- can1.create_oval(16, 16, 184, 184, fill='', outline='lightgrey', width=6)
- affchro.configure(text='',bg='lightgrey')
-
- def aff_infos(e) :
- feninf = Toplevel()
- feninf.config(bg='lightblue')
- geo1=fen1.winfo_geometry()
- geox=fen1.winfo_rootx()
- geoy=fen1.winfo_rooty()
- feninf.geometry("270x260+"+str(geox-50)+"+"+str(geoy-22))
- feninf.title("À propos de Horloge")
- labinf=Label(feninf, bg='lightblue',fg='black',width=50,font=('Arial', 9),
- text= "\nHorloge v.1.3\n\n"
- "Programme écrit en Python / Tkinter\n"
- "et distribué sous licence GNU GPL.\n\n"
- "© 2007 Yves Le Chevalier\n"
- "( yveslechevalier@free.fr )\n\n"
- "Ce programme affiche une horloge \n"
- "avec une alarme, un chronomètre et \n"
- "un affichage digital losque l'on clique \n"
- "sur l'axe des aiguilles. ")
- labinf.pack(pady=5)
- bouf3=Button(feninf, text="Fermer", command=feninf.destroy,bg="orange", fg='brown')
- bouf3.pack(side=BOTTOM,pady=10)
- #feninf.transient()
- feninf.grab_set()
- feninf.wait_window()
-
- def curseur_main(e) :
- fen1.config(cursor='hand2')
-
- def curseur_fleche(e) :
- fen1.config(cursor='arrow')
-
- # main
- fen1 = Tk(className='Horloge')
- fen1.geometry("+500+400")
- fen1.resizable(width=False, height=False)
- can1 = Canvas(fen1, width=200, height=200, bg='lightgrey')
- aigala = can1.create_line(100, 100, 100, 35, fill='', width=1,arrow=LAST)
- aigheu = can1.create_line(100, 100, 100, 50, fill='blue', width=3)
- aigmin = can1.create_line(100, 100, 100, 40, fill='blue', width=2)
- aigsec = can1.create_line(100, 100, 100, 27, fill='yellow', width=1)
- bouala=Button(can1, text="Alarme", command=dessine_alarme, font=('Arial', 7),bg='grey')
- bouala.place(x=2,y=2)
- affala = Label(can1, font=('Arial', 7))
- affala.place(x=4,y=22)
- bouchro=Button(can1, text="Chrono", command=chrono, font=('Arial', 7),bg='grey')
- bouchro.place(x=163,y=2)
- affchro = Label(can1, font=('Arial', 7))
- affchro.place(x=164,y=22)
- bquit=Button(can1, text="Quitter", command=fen1.destroy, font=('Arial', 6),bg='pink',fg='black')
- bquit.place(x=2,y=183)
- afdigi = Label(can1, font=('Arial',9,'bold'),fg="blue")
- afdigi.place(x=78,y=188)
- signature='YLC.gif'
- signat=PhotoImage(file=signature)
- sign=can1.create_image(192,195, image=signat,tag="ylc")
- can1.tag_bind("ylc","<ButtonRelease>",aff_infos)
- can1.tag_bind("ylc","<Enter>",curseur_main)
- can1.tag_bind("ylc","<Leave>",curseur_fleche)
- can1.pack()
-
- dessine_horloge()
- aff_heure()
-
- fen1.mainloop()
-
# horloge analogique
# -*- coding: utf_8 -*-
from Tkinter import *
from math import *
from time import *
from winsound import *
global hala , mala, heuala, iala, ichro, t0, dessala, iafd
hala, mala, heuala, iala, ichro, t0, dessala, iafd = 0, 0, 0, 0, 0, 0, 0, 0
def dessine_horloge() :
can1.create_oval(25, 25, 175, 175, fill='', width=8,outline='gold')
can1.create_oval(20, 20, 180, 180, fill='', width=1)
can1.create_oval(92,92,108,108, fill='gold',outline='black',width=1,tag="axe")
can1.tag_bind("axe","<ButtonRelease>",affich_digit)
can1.tag_bind("axe","<Enter>",curseur_main)
can1.tag_bind("axe","<Leave>",curseur_fleche)
i = 1
while i < 61 :
j = i*((2*pi)/60)
# diametre horloge = 75 centre canvas =100,100
x=(cos(j)*75)+100
y=(sin(j)*75)+100
can1.create_oval(x-1, y-1, x+1, y+1, fill='blue')
if i in (15,30,45,60):
can1.create_oval(x-4, y-4, x+4, y+4, fill='black')
if i in (5,10,20,25,35,40,50,55):
can1.create_oval(x-2, y-2, x+2, y+2, fill='blue')
i = i+1
def affich_digit(e) :
global iafd
if iafd == 0 :
iafd=1
else : iafd=0
def aff_heure() :
global hala, mala, heuala, indala, iafd
dateheure=localtime()
heur=dateheure[3]
minu=dateheure[4]
seco=dateheure[5]
heurd=heur
minud=minu
if str(heur) == str(hala) and str(minu) == str(mala) and iala == 1 :
Beep(800,100)
if heur >12 :
heur = heur -12
if ichro == 1 :
t1=(dateheure[3]*3600)+(dateheure[4]*60)+dateheure[5]
tchro = t1 - t0
hchro = int(tchro/3600)
mchro = int((tchro-(hchro*3600))/60)
schro=tchro-(hchro*3600)-(mchro*60)
affchro.configure(text = '%d' %hchro+'.%02d' %mchro+'.%02d'%schro, bg='white')
# affich heures
heur=heur+(minu/60.00)
j=(heur+9)*((2*pi)/12)
x=(cos(j)*55)+100
y=(sin(j)*55)+100
can1.coords(aigheu, 100, 100, x, y)
# affich minutes
minu=minu+(seco/60.0)
j=(minu+45)*((2*pi)/60)
x=(cos(j)*65)+100
y=(sin(j)*65)+100
can1.coords(aigmin, 100, 100, x, y)
# affich secondes
j=(seco+45)*((2*pi)/60)
x=(cos(j)*70)+100
y=(sin(j)*70)+100
can1.coords(aigsec, 100, 100, x, y)
if ichro == 1 and tchro < 60 :
x=(cos(j)*84)+100
y=(sin(j)*84)+100
can1.create_oval(x-1, y-1, x+1, y+1, fill='green', outline='darkgreen')
#afficher heure digitale
if iafd == 1 :
afdigi.configure(text = '%d' %heurd +" h " +'%02d' %minud)
else : afdigi.configure(text ='',bg='lightgrey')
can1.after(999,aff_heure)
def dessine_alarme() :
global can2 , choixala, iala, dessala
if dessala == 0 :
can2 = Canvas(fen1, width=200, height=50, bg='lightgrey')
can2.pack()
choixala = Label(can2,font=('Arial', 7),fg='darkgreen')
choixala.pack(side=BOTTOM)
curs= Scale(can2, from_=0.0, to=12.00, length=150, sliderlength=7,
resolution=0.01, showvalue=0, orient=HORIZONTAL,
label="Réglage de l'alarme :",command=choix_alarme,font=('Arial', 8),fg='blue')
curs.pack(side=LEFT)
bouon=Button(can2, text="On", command=set_alarme,font=('Arial', 7),bg='grey')
bouon.pack(side=BOTTOM)
dessala = 1
bouoff=Button(can2, text="Off", command=setoff_alarme,font=('Arial', 7),bg='grey')
bouoff.pack(side=BOTTOM)
def choix_alarme(valcurs) :
global hala, mala, heuala
heuala=float(valcurs)
j=(heuala+9)*((2*pi)/12)
x=(cos(j)*70)+100
y=(sin(j)*70)+100
can1.coords(aigala, 100, 100, x, y)
can1.itemconfigure(aigala,fill="red")
hala=int(heuala)
mala=int((heuala - hala) * 60)
dateheure=localtime()
heur=dateheure[3]
if heur > 11 :
hala = hala + 12
choixala.configure(text = "Déclencher l'alarme à " +'% d' %hala +" h. " +'%02d' %mala)
def set_alarme() :
global indala, iala, dessala
dessala = 0
if iala ==1 :
can1.delete(indala)
bouala.config(bg='red')
j=(heuala+9)*((2*pi)/12)
x=(cos(j)*75)+100
y=(sin(j)*75)+100
indala=can1.create_oval(x-2, y-2, x+2, y+2, fill='red')
iala =1
affala.configure(text = '%d' %hala +" h." +'%02d' %mala,bg='white')
can2.destroy()
Beep(1000,20)
def setoff_alarme() :
global indala, iala, dessala
if dessala == 1 :
can2.destroy()
dessala = 0
bouala.config(bg='grey')
can1.itemconfigure(aigala,fill="lightgrey")
if iala ==1 :
can1.delete(indala)
iala =0
affala.configure(text = '',bg='lightgrey')
Beep(100,50)
def chrono() :
global ichro, t0
if ichro == 0 :
ichro = 1
dateheure=localtime()
t0=(dateheure[3]*3600)+(dateheure[4]*60)+dateheure[5]
bouchro.config(bg='green')
elif ichro == 1 :
ichro = 2
bouchro.config(bg='lightblue')
else :
ichro = 0
bouchro.config(bg='grey')
can1.create_oval(16, 16, 184, 184, fill='', outline='lightgrey', width=6)
affchro.configure(text='',bg='lightgrey')
def aff_infos(e) :
feninf = Toplevel()
feninf.config(bg='lightblue')
geo1=fen1.winfo_geometry()
geox=fen1.winfo_rootx()
geoy=fen1.winfo_rooty()
feninf.geometry("270x260+"+str(geox-50)+"+"+str(geoy-22))
feninf.title("À propos de Horloge")
labinf=Label(feninf, bg='lightblue',fg='black',width=50,font=('Arial', 9),
text= "\nHorloge v.1.3\n\n"
"Programme écrit en Python / Tkinter\n"
"et distribué sous licence GNU GPL.\n\n"
"© 2007 Yves Le Chevalier\n"
"( yveslechevalier@free.fr )\n\n"
"Ce programme affiche une horloge \n"
"avec une alarme, un chronomètre et \n"
"un affichage digital losque l'on clique \n"
"sur l'axe des aiguilles. ")
labinf.pack(pady=5)
bouf3=Button(feninf, text="Fermer", command=feninf.destroy,bg="orange", fg='brown')
bouf3.pack(side=BOTTOM,pady=10)
#feninf.transient()
feninf.grab_set()
feninf.wait_window()
def curseur_main(e) :
fen1.config(cursor='hand2')
def curseur_fleche(e) :
fen1.config(cursor='arrow')
# main
fen1 = Tk(className='Horloge')
fen1.geometry("+500+400")
fen1.resizable(width=False, height=False)
can1 = Canvas(fen1, width=200, height=200, bg='lightgrey')
aigala = can1.create_line(100, 100, 100, 35, fill='', width=1,arrow=LAST)
aigheu = can1.create_line(100, 100, 100, 50, fill='blue', width=3)
aigmin = can1.create_line(100, 100, 100, 40, fill='blue', width=2)
aigsec = can1.create_line(100, 100, 100, 27, fill='yellow', width=1)
bouala=Button(can1, text="Alarme", command=dessine_alarme, font=('Arial', 7),bg='grey')
bouala.place(x=2,y=2)
affala = Label(can1, font=('Arial', 7))
affala.place(x=4,y=22)
bouchro=Button(can1, text="Chrono", command=chrono, font=('Arial', 7),bg='grey')
bouchro.place(x=163,y=2)
affchro = Label(can1, font=('Arial', 7))
affchro.place(x=164,y=22)
bquit=Button(can1, text="Quitter", command=fen1.destroy, font=('Arial', 6),bg='pink',fg='black')
bquit.place(x=2,y=183)
afdigi = Label(can1, font=('Arial',9,'bold'),fg="blue")
afdigi.place(x=78,y=188)
signature='YLC.gif'
signat=PhotoImage(file=signature)
sign=can1.create_image(192,195, image=signat,tag="ylc")
can1.tag_bind("ylc","<ButtonRelease>",aff_infos)
can1.tag_bind("ylc","<Enter>",curseur_main)
can1.tag_bind("ylc","<Leave>",curseur_fleche)
can1.pack()
dessine_horloge()
aff_heure()
fen1.mainloop()
Conclusion
Rien de spectaculaire en terme de code, mais ça peut servir comme petit exemple python pour des débutants.
Historique
- 21 novembre 2008 16:43:09 :
- J'avais oublié de joindre l'image YLC.gif à mon Zip. Ceci est corrigé.
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
scrollbar dans scrollbox avec TKinter [ par MHI ]
Est-ce que quelqu'un sait comment ajouter les scrollbar à une scrollbox :J'ai essayé ceci :lstFile = Tkinter.Listbox(frmMain)lstFile.place(x = 20, y =
checkButton avec TKinter [ par MHI ]
comment faire pour tester si un checkButton est coché ?
Probleme avec TKinter [ par titasse ]
Bonjour, je debute en python. J'ai un probleme lorsque je veux importer TKinter avec la commande from TKinter import * j'ai le message suivant : Imp
au sujet de Tkinter et le module turtle [ par nico1900 ]
from turtle import *forward(120)left(90) color('red') forward(80)bon en fait je voulais tester le module turtle avec l e code ci-d
Un Canvas comme dans Tkinter, mais pour wxPython [ par samurize ]
Slt tout le monde. Voila tout est dans le titre (ou a peu pres ) : Je suis à la recherche d'un module pouvant s'integrer da
Taille de widgets sous Tkinter [ par Uims ]
Bonjour, Quelqu"un saurait comment definir la taille d'un widgets sous tkinter??? Exemple: fen 1 = Tk(taille=600) J'espere que je me fait comprend
Ouverture d'un fichier windows (avec Tkinter) [ par Uims ]
Bonjour, Je travaille sous python et Tkinter et j'aurai voulu savoir comment dire a python de demarrer (comme on clique sur un fichier) une applicati
Tkinter et Python [ par Telimektar1er ]
Voila j'ai commencé e python il y a une semaine et jusqu à aujourd'hui aucun problème. Mais voilà, je viens de commencer la cr
help, faire un mastermind en python et en tkinter avant le 24 !!! [ par Crick132 ]
je suis étudiante en 2ème année, je dois réaliser un mastermind en python avec 8 couleurs et 5 combinaisons possibles.si quelqu'un
Importer une image dans Tkinter... [ par skools ]
Bonjour à tous, Et pardon à ceux à qui j'ai envoyé des messages perso, je n'arrivais pas à poster un suget dans le forum... Voilà, après des heures d
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Logiciels
974 Application Server (12.2.4.0)974 APPLICATION SERVER (12.2.4.0)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP mySongBook Player (1.0.0)MYSONGBOOK PLAYER (1.0.0)mySongBook Player est un logiciel gratuit permettant l'accès à une archive de tablatures/partitio... Cliquez pour télécharger mySongBook Player
|