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
   |  
#!/usr/bin/python
# Exemple de calcul cle ean 13 (homere@modulonet.fr 12/2005)
from Tkinter import *
 
 
class calculean:
    def __init__(self,parent):
        # 1- cree et positionne le champ de texte
        self.ean = Entry(parent)
 
        self.ean.grid( row=0 )
        # 2- cree un bouton
        b = Button(parent, text='Validez !',
                   command=self.pressed)
        b.grid( row=1, column=0 )
        # Et un bouton pour quitter
        b = Button(parent, text='Quitter',
                   command=parent.quit )
        b.grid( row=1, column=1 )
 
    def pressed(self):
        # appele lorsqu'on appuie le bouton
        texte = self.ean.get()
        if len(texte) < 12 :
                    chaine = Label(fen,fg='red', text = " Il faut 12 chiffres").grid(row=3)
 
        self.a1 = (float(texte[0])); self.a2 = (float(texte[2]));self.a3 = float(texte[4]); self.a4 = float(texte[6]); self.a5 = float(texte[8]); self.a6 = float(texte[10]);
        self.b1 = (float(texte[1])); self.b2 = (float(texte[3]));self.b3 = float(texte[5]); self.b4 = float(texte[7]); self.b5 = float(texte[9]); self.b6 = float(texte[11]);
        a= self.a1+self.a2+self.a3+self.a4+self.a5+self.a6
        b= self.b1+self.b2+self.b3+self.b4+self.b5+self.b6
        cle = (a+(b*3))
        cle = str(int(cle))
        cle = cle[-1]
	cle = 10- int(cle)
        if cle > 9:
                cle = 0
        chaine = Label(fen,fg='blue', text = 'La cle est : ' + str(cle)).grid(row=3)
 
 
 
 
 
fen = Tk()
 
fen.title('code ean 13 ')
E = calculean(fen)
 
 
fen.mainloop() # lance l'application | 
Partager