Double afficheur 7 segments

Soyez le premier à donner votre avis sur cette source.

Vue 10 550 fois - Téléchargée 360 fois

Description

Afficheur double destiné à afficher un nombre compris entre 0 et 99.
Par défaut, l'afficheur affiche des nombres générés aléatoirement.

Source / Exemple :


# -*- coding: cp1252 -*-
# Afficheur 7 segments
# Immaginé et développé par Amaury

# Initialisation
from Tkinter import*
import time
import random
chiffre={0:[1,2,3,4,5,6], 1:[2,3], 2:[1,2,7,5,4], 3:[1,2,3,4,7], 4:[6,7,2,3], 5:[1,6,7,3,4], 6:[1,6,5,4,3,7], 7:[1,2,3], 8:[1,2,3,4,5,6,7], 9:[1,2,3,4,6,7]}
coded={1:[30,50,80,50],7:[30,100,80,100],4:[30,150,80,150],6:[25,55,25,95],2:[85,55,85,95],3:[85,105,85,145],5:[25,105,25,145]}
codeu={1:[120,50,170,50],7:[120,100,170,100],4:[120,150,170,150],6:[115,55,115,95],2:[175,55,175,95],3:[175,105,175,145],5:[115,105,115,145]}
d=0
u=0

# Dessin du Canevas
root=Tk()
can=Canvas(width=200,height=200)
can.pack()

# Dessin des afficheurs
can.create_rectangle(0,0,200,200,fill="white",outline="white")
can.create_rectangle(10,30,190,170,width=2,fill="grey")
can.create_line(100,30,100,170,width=2)

while 1:
    d=0
    u=0
    consigne=random.randint(0,99)                           #Génération aléatoire, à supprimer pour afficher une acquisition
    # Digits au repos
    can.create_line(30,50,80,50,width=5,fill="pink")
    can.create_line(30,100,80,100,width=5,fill="pink")
    can.create_line(30,150,80,150,width=5,fill="pink")
    can.create_line(120,50,170,50,width=5,fill="pink")
    can.create_line(120,100,170,100,width=5,fill="pink")
    can.create_line(120,150,170,150,width=5,fill="pink")
    can.create_line(25,55,25,95,width=5,fill="pink")
    can.create_line(115,55,115,95,width=5,fill="pink")
    can.create_line(85,55,85,95,width=5,fill="pink")
    can.create_line(175,55,175,95,width=5,fill="pink")
    can.create_line(25,105,25,145,width=5,fill="pink")
    can.create_line(115,105,115,145,width=5,fill="pink")
    can.create_line(85,105,85,145,width=5,fill="pink")
    can.create_line(175,105,175,145,width=5,fill="pink")
    root.update()
    
    #Décomposition de la valeur à afficher en unités et dixaines
    while(consigne>=10):
        consigne=consigne-10
        d=d+1
    u=consigne
        
    segu=list(chiffre [u])
    segd=list(chiffre [d])
    # Digits allumés
    for i in segu:
        can.create_line(codeu[i],width=5,fill="red")
        
    for j in segd:
        can.create_line(coded[j],width=5,fill="red")

    root.update()            
    time.sleep(0.5)                                         #Période de rafraichissement

Conclusion :


Peut être intégrée dans une application plus importante

Codes Sources

A voir également

Ajouter un commentaire

Commentaire

pumpeth0
Messages postés
2
Date d'inscription
jeudi 22 décembre 2011
Statut
Membre
Dernière intervention
22 décembre 2011
-
Merci pour ce code source qui m'a bien aidé.

Je l'ai modifié pour pouvoir avoir 1, 2, 3, 4 ou 5 digits, et l'intégrer directement dans une classe. Le voici, si au cas où ça peut rendre service.

import Tkinter as Tk

##Creation des modeles d'afficheurs 7 segments
class Afficheur5Digits() :
def __init__ (self, frameParent) :
self.chiffre={0:[1,2,3,4,5,6], 1:[2,3], 2:[1,2,7,5,4], 3:[1,2,3,4,7], 4:[6,7,2,3], 5:[1,6,7,3,4], 6:[6,5,4,3,7], 7:[1,2,3], 8:[1,2,3,4,5,6,7], 9:[1,2,3,6,7]}
self.codep={1:[13,5,37,5],7:[16,25,34,25],4:[13,45,37,45],6:[13,5,13,23],2:[37,5,37,23],3:[37,27,37,45],5:[13,27,13,45]}
self.codem={1:[63,5,87,5],7:[66,25,84,25],4:[63,45,87,45],6:[63,5,63,23],2:[87,5,87,23],3:[87,27,87,45],5:[63,27,63,45]}
self.codec={1:[113,5,137,5],7:[116,25,134,25],4:[113,45,137,45],6:[113,5,113,23],2:[137,5,137,23],3:[137,27,137,45],5:[113,27,113,45]}
self.coded={1:[163,5,187,5],7:[166,25,184,25],4:[163,45,187,45],6:[163,5,163,23],2:[187,5,187,23],3:[187,27,187,45],5:[163,27,163,45]}
self.codeu={1:[213,5,237,5],7:[216,25,234,25],4:[213,45,237,45],6:[213,5,213,23],2:[237,5,237,23],3:[237,27,237,45],5:[213,27,213,45]}

p=0
m=0
c=0
d=0
u=0

# Dessin du Canevas
self.can=Tk.Canvas(frameParent, width=250,height=50)
self.can.pack()

# Dessin des afficheurs
self.can.create_rectangle(0,0,250,50,fill="gray",outline="white")
self.can.create_line(50,0,50,50,width=2)
self.can.create_line(100,0,100,50,width=2)
self.can.create_line(150,0,150,50,width=2)
self.can.create_line(200,0,200,50,width=2)

# Digit des dizaines de milliers
##Batonnets de gauche
self.can.create_line(13,5,13,23,width=3,fill="pink")
self.can.create_line(13,27,13,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(37,5,37,23,width=3,fill="pink")
self.can.create_line(37,27,37,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(16,25,34,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(13,5,37,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(13,45,37,45,width=3,fill="pink")
# Digit des milliers
##Batonnets de gauche
self.can.create_line(63,5,63,23,width=3,fill="pink")
self.can.create_line(63,27,63,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(87,5,87,23,width=3,fill="pink")
self.can.create_line(87,27,87,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(66,25,84,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(63,5,87,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(63,45,87,45,width=3,fill="pink")
# Digit des centaines
##Batonnets de gauche
self.can.create_line(113,5,113,23,width=3,fill="pink")
self.can.create_line(113,27,113,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(137,5,137,23,width=3,fill="pink")
self.can.create_line(137,27,137,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(116,25,134,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(113,5,137,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(113,45,137,45,width=3,fill="pink")
# Digit des dizaines
##Batonnets de gauche
self.can.create_line(163,5,163,23,width=3,fill="pink")
self.can.create_line(163,27,163,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(187,5,187,23,width=3,fill="pink")
self.can.create_line(187,27,187,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(166,25,184,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(163,5,187,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(163,45,187,45,width=3,fill="pink")
# Digit des unites
##Batonnets de gauche
self.can.create_line(213,5,213,23,width=3,fill="pink")
self.can.create_line(213,27,213,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(237,5,237,23,width=3,fill="pink")
self.can.create_line(237,27,237,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(216,25,234,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(213,5,237,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(213,45,237,45,width=3,fill="pink")

self.can.update()

def majAffichage(self, consigne) :
p=0
m=0
c=0
d=0
u=0

# Digit des dizaines de milliers
##Batonnets de gauche
self.can.create_line(13,5,13,23,width=3,fill="pink")
self.can.create_line(13,27,13,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(37,5,37,23,width=3,fill="pink")
self.can.create_line(37,27,37,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(16,25,34,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(13,5,37,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(13,45,37,45,width=3,fill="pink")
# Digit des milliers
##Batonnets de gauche
self.can.create_line(63,5,63,23,width=3,fill="pink")
self.can.create_line(63,27,63,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(87,5,87,23,width=3,fill="pink")
self.can.create_line(87,27,87,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(66,25,84,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(63,5,87,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(63,45,87,45,width=3,fill="pink")
# Digit des centaines
##Batonnets de gauche
self.can.create_line(113,5,113,23,width=3,fill="pink")
self.can.create_line(113,27,113,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(137,5,137,23,width=3,fill="pink")
self.can.create_line(137,27,137,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(116,25,134,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(113,5,137,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(113,45,137,45,width=3,fill="pink")
# Digit des dizaines
##Batonnets de gauche
self.can.create_line(163,5,163,23,width=3,fill="pink")
self.can.create_line(163,27,163,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(187,5,187,23,width=3,fill="pink")
self.can.create_line(187,27,187,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(166,25,184,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(163,5,187,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(163,45,187,45,width=3,fill="pink")
# Digit des unites
##Batonnets de gauche
self.can.create_line(213,5,213,23,width=3,fill="pink")
self.can.create_line(213,27,213,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(237,5,237,23,width=3,fill="pink")
self.can.create_line(237,27,237,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(216,25,234,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(213,5,237,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(213,45,237,45,width=3,fill="pink")

self.can.update()

#Décomposition de la valeur à afficher en unites, dizaines, centaines, milliers et dizaines de milliers
while (consigne>=10000):
consigne=consigne-10000
p=p+1
while (consigne>=1000) :
consigne=consigne-1000
m=m+1
while (consigne>=100) :
consigne=consigne-100
c=c+1
while (consigne>=10) :
consigne=consigne-10
d=d+1
u=consigne

segu=list(self.chiffre [u])
segd=list(self.chiffre [d])
segc=list(self.chiffre [c])
segm=list(self.chiffre [m])
segp=list(self.chiffre [p])

# Digits allumés
for i in segu:
self.can.create_line(self.codeu[i],width=3,fill="red")
for j in segd:
self.can.create_line(self.coded[j],width=3,fill="red")
for k in segc:
self.can.create_line(self.codec[k],width=3,fill="red")
for l in segm:
self.can.create_line(self.codem[l],width=3,fill="red")
for m in segp:
self.can.create_line(self.codep[m],width=3,fill="red")

self.can.update()

class Afficheur4Digits() :
def __init__ (self, frameParent) :
self.chiffre={0:[1,2,3,4,5,6], 1:[2,3], 2:[1,2,7,5,4], 3:[1,2,3,4,7], 4:[6,7,2,3], 5:[1,6,7,3,4], 6:[6,5,4,3,7], 7:[1,2,3], 8:[1,2,3,4,5,6,7], 9:[1,2,3,6,7]}
self.codem={1:[13,5,37,5],7:[16,25,34,25],4:[13,45,37,45],6:[13,5,13,23],2:[37,5,37,23],3:[37,27,37,45],5:[13,27,13,45]}
self.codec={1:[63,5,87,5],7:[66,25,84,25],4:[63,45,87,45],6:[63,5,63,23],2:[87,5,87,23],3:[87,27,87,45],5:[63,27,63,45]}
self.coded={1:[113,5,137,5],7:[116,25,134,25],4:[113,45,137,45],6:[113,5,113,23],2:[137,5,137,23],3:[137,27,137,45],5:[113,27,113,45]}
self.codeu={1:[163,5,187,5],7:[166,25,184,25],4:[163,45,187,45],6:[163,5,163,23],2:[187,5,187,23],3:[187,27,187,45],5:[163,27,163,45]}

m=0
c=0
d=0
u=0

# Dessin du Canevas
self.can=Tk.Canvas(frameParent, width=200,height=50)
self.can.pack()

# Dessin des afficheurs
self.can.create_rectangle(0,0,200,50,fill="gray",outline="white")
self.can.create_line(50,0,50,50,width=2)
self.can.create_line(100,0,100,50,width=2)
self.can.create_line(150,0,150,50,width=2)

# Digit des milliers
##Batonnets de gauche
self.can.create_line(13,5,13,23,width=3,fill="pink")
self.can.create_line(13,27,13,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(37,5,37,23,width=3,fill="pink")
self.can.create_line(37,27,37,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(16,25,34,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(13,5,37,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(13,45,37,45,width=3,fill="pink")

# Digit des centaines
##Batonnets de gauche
self.can.create_line(63,5,63,23,width=3,fill="pink")
self.can.create_line(63,27,63,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(87,5,87,23,width=3,fill="pink")
self.can.create_line(87,27,87,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(66,25,84,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(63,5,87,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(63,45,87,45,width=3,fill="pink")

# Digit des dizaines
##Batonnets de gauche
self.can.create_line(113,5,113,23,width=3,fill="pink")
self.can.create_line(113,27,113,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(137,5,137,23,width=3,fill="pink")
self.can.create_line(137,27,137,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(116,25,134,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(113,5,137,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(113,45,137,45,width=3,fill="pink")

# Digit des unites
##Batonnets de gauche
self.can.create_line(163,5,163,23,width=3,fill="pink")
self.can.create_line(163,27,163,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(187,5,187,23,width=3,fill="pink")
self.can.create_line(187,27,187,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(166,25,184,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(163,5,187,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(163,45,187,45,width=3,fill="pink")

self.can.update()

def majAffichage(self, consigne) :
m=0
c=0
d=0
u=0

# Digit des milliers
##Batonnets de gauche
self.can.create_line(13,5,13,23,width=3,fill="pink")
self.can.create_line(13,27,13,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(37,5,37,23,width=3,fill="pink")
self.can.create_line(37,27,37,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(16,25,34,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(13,5,37,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(13,45,37,45,width=3,fill="pink")

# Digit des centaines
##Batonnets de gauche
self.can.create_line(63,5,63,23,width=3,fill="pink")
self.can.create_line(63,27,63,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(87,5,87,23,width=3,fill="pink")
self.can.create_line(87,27,87,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(66,25,84,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(63,5,87,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(63,45,87,45,width=3,fill="pink")

# Digit des dizaines
##Batonnets de gauche
self.can.create_line(113,5,113,23,width=3,fill="pink")
self.can.create_line(113,27,113,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(137,5,137,23,width=3,fill="pink")
self.can.create_line(137,27,137,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(116,25,134,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(113,5,137,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(113,45,137,45,width=3,fill="pink")

# Digit des unites
##Batonnets de gauche
self.can.create_line(163,5,163,23,width=3,fill="pink")
self.can.create_line(163,27,163,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(187,5,187,23,width=3,fill="pink")
self.can.create_line(187,27,187,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(166,25,184,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(163,5,187,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(163,45,187,45,width=3,fill="pink")

self.can.update()

#Décomposition de la valeur à afficher en unites, dizaines, centaines, milliers
while (consigne>=1000) :
consigne=consigne-1000
m=m+1
while (consigne>=100) :
consigne=consigne-100
c=c+1
while (consigne>=10) :
consigne=consigne-10
d=d+1
u=consigne

segu=list(self.chiffre [u])
segd=list(self.chiffre [d])
segc=list(self.chiffre [c])
segm=list(self.chiffre [m])

# Digits allumés
for i in segu:
self.can.create_line(self.codeu[i],width=3,fill="red")
for j in segd:
self.can.create_line(self.coded[j],width=3,fill="red")
for k in segc:
self.can.create_line(self.codec[k],width=3,fill="red")
for l in segm:
self.can.create_line(self.codem[l],width=3,fill="red")

self.can.update()

class Afficheur3Digits() :
def __init__ (self, frameParent) :
self.chiffre={0:[1,2,3,4,5,6], 1:[2,3], 2:[1,2,7,5,4], 3:[1,2,3,4,7], 4:[6,7,2,3], 5:[1,6,7,3,4], 6:[6,5,4,3,7], 7:[1,2,3], 8:[1,2,3,4,5,6,7], 9:[1,2,3,6,7]}
self.codec={1:[13,5,37,5],7:[16,25,34,25],4:[13,45,37,45],6:[13,5,13,23],2:[37,5,37,23],3:[37,27,37,45],5:[13,27,13,45]}
self.coded={1:[63,5,87,5],7:[66,25,84,25],4:[63,45,87,45],6:[63,5,63,23],2:[87,5,87,23],3:[87,27,87,45],5:[63,27,63,45]}
self.codeu={1:[113,5,137,5],7:[116,25,134,25],4:[113,45,137,45],6:[113,5,113,23],2:[137,5,137,23],3:[137,27,137,45],5:[113,27,113,45]}

c=0
d=0
u=0

# Dessin du Canevas
self.can=Tk.Canvas(frameParent, width=150,height=50)
self.can.pack()

# Dessin des afficheurs
self.can.create_rectangle(0,0,150,50,fill="gray",outline="white")
self.can.create_line(50,0,50,50,width=2)
self.can.create_line(100,0,100,50,width=2)

# Digit des centaines
##Batonnets de gauche
self.can.create_line(13,5,13,23,width=3,fill="pink")
self.can.create_line(13,27,13,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(37,5,37,23,width=3,fill="pink")
self.can.create_line(37,27,37,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(16,25,34,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(13,5,37,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(13,45,37,45,width=3,fill="pink")

# Digit des dizaines
##Batonnets de gauche
self.can.create_line(63,5,63,23,width=3,fill="pink")
self.can.create_line(63,27,63,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(87,5,87,23,width=3,fill="pink")
self.can.create_line(87,27,87,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(66,25,84,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(63,5,87,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(63,45,87,45,width=3,fill="pink")

# Digit des unites
##Batonnets de gauche
self.can.create_line(113,5,113,23,width=3,fill="pink")
self.can.create_line(113,27,113,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(137,5,137,23,width=3,fill="pink")
self.can.create_line(137,27,137,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(116,25,134,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(113,5,137,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(113,45,137,45,width=3,fill="pink")

self.can.update()

def majAffichage(self, consigne) :
c=0
d=0
u=0

# Digit des centaines
##Batonnets de gauche
self.can.create_line(13,5,13,23,width=3,fill="pink")
self.can.create_line(13,27,13,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(37,5,37,23,width=3,fill="pink")
self.can.create_line(37,27,37,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(16,25,34,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(13,5,37,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(13,45,37,45,width=3,fill="pink")

# Digit des dizaines
##Batonnets de gauche
self.can.create_line(63,5,63,23,width=3,fill="pink")
self.can.create_line(63,27,63,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(87,5,87,23,width=3,fill="pink")
self.can.create_line(87,27,87,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(66,25,84,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(63,5,87,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(63,45,87,45,width=3,fill="pink")

# Digit des unites
##Batonnets de gauche
self.can.create_line(113,5,113,23,width=3,fill="pink")
self.can.create_line(113,27,113,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(137,5,137,23,width=3,fill="pink")
self.can.create_line(137,27,137,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(116,25,134,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(113,5,137,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(113,45,137,45,width=3,fill="pink")

self.can.update()

#Décomposition de la valeur à afficher en unites, dizaines, centaines
while (consigne>=100) :
consigne=consigne-100
c=c+1
while (consigne>=10) :
consigne=consigne-10
d=d+1
u=consigne

segu=list(self.chiffre [u])
segd=list(self.chiffre [d])
segc=list(self.chiffre [c])

# Digits allumés
for i in segu:
self.can.create_line(self.codeu[i],width=3,fill="red")
for j in segd:
self.can.create_line(self.coded[j],width=3,fill="red")
for k in segc:
self.can.create_line(self.codec[k],width=3,fill="red")

self.can.update()

class Afficheur2Digits() :
def __init__ (self, frameParent) :
self.chiffre={0:[1,2,3,4,5,6], 1:[2,3], 2:[1,2,7,5,4], 3:[1,2,3,4,7], 4:[6,7,2,3], 5:[1,6,7,3,4], 6:[6,5,4,3,7], 7:[1,2,3], 8:[1,2,3,4,5,6,7], 9:[1,2,3,6,7]}
self.coded={1:[13,5,37,5],7:[16,25,34,25],4:[13,45,37,45],6:[13,5,13,23],2:[37,5,37,23],3:[37,27,37,45],5:[13,27,13,45]}
self.codeu={1:[63,5,87,5],7:[66,25,84,25],4:[63,45,87,45],6:[63,5,63,23],2:[87,5,87,23],3:[87,27,87,45],5:[63,27,63,45]}

d=0
u=0

# Dessin du Canevas
self.can=Tk.Canvas(frameParent, width=100,height=50)
self.can.pack()

# Dessin des afficheurs
self.can.create_rectangle(0,0,100,50,fill="gray",outline="white")
self.can.create_line(50,0,50,50,width=2)

# Digit des dizaines
##Batonnets de gauche
self.can.create_line(13,5,13,23,width=3,fill="pink")
self.can.create_line(13,27,13,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(37,5,37,23,width=3,fill="pink")
self.can.create_line(37,27,37,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(16,25,34,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(13,5,37,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(13,45,37,45,width=3,fill="pink")

# Digit des unites
##Batonnets de gauche
self.can.create_line(63,5,63,23,width=3,fill="pink")
self.can.create_line(63,27,63,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(87,5,87,23,width=3,fill="pink")
self.can.create_line(87,27,87,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(66,25,84,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(63,5,87,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(63,45,87,45,width=3,fill="pink")

self.can.update()

def majAffichage(self, consigne) :
d=0
u=0

# Digit des dizaines
##Batonnets de gauche
self.can.create_line(13,5,13,23,width=3,fill="pink")
self.can.create_line(13,27,13,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(37,5,37,23,width=3,fill="pink")
self.can.create_line(37,27,37,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(16,25,34,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(13,5,37,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(13,45,37,45,width=3,fill="pink")

# Digit des unites
##Batonnets de gauche
self.can.create_line(63,5,63,23,width=3,fill="pink")
self.can.create_line(63,27,63,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(87,5,87,23,width=3,fill="pink")
self.can.create_line(87,27,87,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(66,25,84,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(63,5,87,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(63,45,87,45,width=3,fill="pink")

self.can.update()

#Décomposition de la valeur à afficher en unites, dizaines, centaines, milliers et dizaines de milliers
while (consigne>=10) :
consigne=consigne-10
d=d+1
u=consigne

segu=list(self.chiffre [u])
segd=list(self.chiffre [d])

# Digits allumés
for i in segu:
self.can.create_line(self.codeu[i],width=3,fill="red")
for j in segd:
self.can.create_line(self.coded[j],width=3,fill="red")

self.can.update()

##Creation des modeles d'afficheurs 7 segments
class Afficheur1Digits() :
def __init__ (self, frameParent) :
self.chiffre={0:[1,2,3,4,5,6], 1:[2,3], 2:[1,2,7,5,4], 3:[1,2,3,4,7], 4:[6,7,2,3], 5:[1,6,7,3,4], 6:[6,5,4,3,7], 7:[1,2,3], 8:[1,2,3,4,5,6,7], 9:[1,2,3,6,7]}
self.codeu={1:[13,5,37,5],7:[16,25,34,25],4:[13,45,37,45],6:[13,5,13,23],2:[37,5,37,23],3:[37,27,37,45],5:[13,27,13,45]}

u=0

# Dessin du Canevas
self.can=Tk.Canvas(frameParent, width=50,height=50)
self.can.pack()

# Dessin des afficheurs
self.can.create_rectangle(0,0,50,50,fill="gray",outline="white")

# Digit des unites
##Batonnets de gauche
self.can.create_line(13,5,13,23,width=3,fill="pink")
self.can.create_line(13,27,13,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(37,5,37,23,width=3,fill="pink")
self.can.create_line(37,27,37,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(16,25,34,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(13,5,37,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(13,45,37,45,width=3,fill="pink")

self.can.update()

def majAffichage(self, consigne) :
u=0

# Digit des unites
##Batonnets de gauche
self.can.create_line(13,5,13,23,width=3,fill="pink")
self.can.create_line(13,27,13,45,width=3,fill="pink")
##Batonnets de droite
self.can.create_line(37,5,37,23,width=3,fill="pink")
self.can.create_line(37,27,37,45,width=3,fill="pink")
##Batonnet du milieu
self.can.create_line(16,25,34,25,width=3,fill="pink")
##Batonnet du haut
self.can.create_line(13,5,37,5,width=3,fill="pink")
##Batonnet du bas
self.can.create_line(13,45,37,45,width=3,fill="pink")

self.can.update()

#Décomposition de la valeur à afficher en unites, dizaines, centaines, milliers et dizaines de milliers
u=consigne

segu=list(self.chiffre [u])

# Digits allumés
for i in segu:
self.can.create_line(self.codeu[i],width=3,fill="red")

self.can.update()

Et pour utiliser un afficheur :

root = Tk()
frameParent = Tk.Frame(root)

afficheur = Afficheur1Digits(frameParent)

consigne = 9
afficheur.majAffichage(consigne)

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.