Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- # -*- coding: utf8 -*-
- # Copyright © 2016 Ordinosor <https://twitter.com/Ordinosor>
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>
- #==== IMPORTATION DES MODULES =============================================================================
- from tkinter import* # Importation du module tkinter
- import time
- from datetime import datetime
- import math
- import threading
- #==== CLASSE ==============================================================================================
- class Horloge(object) :
- "Instanciation de l'objet 'horloge'"
- def __init__(self) :
- "Constructeur de la classe Horloge"
- #----------------------------------------------------------------------------------------------------------
- def horloge(self) :
- "Création de l'horloge"
- self.fenetre = Tk()
- self.fenetre.title('Horloge de Benoît')
- self.can = Canvas(self.fenetre, width = 300, height = 300, bg='white')
- self.can.grid()
- self.can.create_oval(15, 15, 285, 285, outline = 'navy', width = 3) # Création du plateau de l'horloge.
- self.can.create_oval(145, 145, 155, 155, fill = 'black', width = 3) # Création du petit cercle noir au centre de l'horloge.
- self.numbers_coords = [[210, 50],[250, 90],[272, 150],[255, 212],[210, 255],[150, 270],[95, 255],[50, 210],[28, 150],[47, 95],[92, 52],[150, 35]]
- for i in range(0, len(self.numbers_coords)) : # Placement des chiffres de l'horloge
- self.can.create_text(self.numbers_coords[i][0], self.numbers_coords[i][1], text= str(i+1), font = 'Times 14 bold italic', fill = 'black')
- self.hour = self.can.create_line(0, 0, 0, 0, fill = 'black', width = 6) # aiguille des heures
- self.minute = self.can.create_line(0, 0, 0, 0, fill = 'black', width = 6) # aiguille des minutes
- self.second = self.can.create_line(0, 0, 0, 0, fill = 'red', width = 3) # aiguille des secondes
- self.move() # Appel de la méthode move() pour faire avancer les aiguilles
- self.fenetre.mainloop() # Déclenchement du réceptionnaire d'événements
- #----------------------------------------------------------------------------------------------------------
- def move(self):
- #Méthode permettant aux aiguilles d'avancer
- self.now = time.localtime() # Méthode qui fournit l'heure locale
- self.can.coords(self.hour, 150, 150, 150 + math.cos(self.now[3]*math.pi/6+self.now[4]*math.pi/360-math.pi/2)*55,150 + math.sin(self.now[3]*math.pi/6+self.now[4]*math.pi/360-math.pi/2)*55)
- self.can.coords(self.minute, 150, 150, 150 + math.cos(self.now[4]*math.pi/30+self.now[5]*math.pi/1800-math.pi/2)*85, 150 + math.sin(self.now[4]*math.pi/30+self.now[5]*math.pi/1800-math.pi/2)*85),
- self.can.coords(self.second, 150, 150, 150 + math.cos(self.now[5]*math.pi/30-math.pi/2)*90, 150 + math.sin(self.now[5]*math.pi/30-math.pi/2)*90)
- # Récursivité : La méthode move s'appelle elle-même toutes les mille millièmes de secondes (c'est-à-dire toutes les secondes) grâce à la méthode after:
- self.can.after(1000, self.move)
- ###### MAIN PROGRAMM ######################################################################################
- if __name__ == "__main__":
- horloge = Horloge() # Création de l'objet horloge
- horloge.horloge() # Appel de la méthode horloge de la classe éponyme.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement