Ben c'est juste un afficheur 7 segemnts(affiche les nombres de 0 à 9)relié a votre propre clavier numérique.
Source / Exemple :
# -*- coding: iso8859-15 -*-
from Tkinter import*
dic={1: (70, 45, 130, 35), 2: (130, 45, 140, 95), 3: (130, 105, 140, 165), 4: (130, 165, 70, 175),
5: (60, 165, 70, 105), 6: (70, 95, 60, 45), 7: (70, 95, 130, 105)}
code={1:(2,3),2:(1,2,7,5,4),3:(1,2,7,3,4),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:(6,1,2,3,4,7),0:(1,2,3,4,5,6)}
class Afficheur(Frame):
def __init__(self):
Frame.__init__(self)
self.master.title("::.Afficheur Sept Segments.::")
self.configure(bg="grey40",bd=0,relief=FLAT)
self.master.resizable(width=False, height=False)
self.master.protocol("WM_DELETE_WINDOW", self.quitter)
self.pack(padx =8, pady =8)
self.lst=[]
self.build()
def build(self):
self.can=Canvas(self,bg='black',relief=FLAT,width =200,height =200)
self.can.grid(row=0,column=0)
liste=[]
for i in [1,2,3,4,5,6,7]: #Mise en place des segments de l'afficheur
v=dic[i]
liste.append(v)
for (w,x,y,z) in liste:
p=self.can.create_rectangle(w,x,y,z,fill='black')
self.lst.append(p)
liste=[]
fram=Frame(self,bd=0,relief=FLAT,bg='white')
fram.grid(row=0,column=1)
Button(fram,text='1',font='arial 10 bold',bg='white',relief=FLAT,
command= lambda arg=1: self.affiche(arg)).grid(row=1,column=1,padx=2,pady=2) #Mise en place des boutons du clavier numerique
Button(fram,text='2',font='arial 10 bold',bg='white',relief=FLAT,
command= lambda arg=2: self.affiche(arg)).grid(row=1,column=2,padx=2,pady=2)
Button(fram,text='3',font='arial 10 bold',bg='white',relief=FLAT,
command= lambda arg=3: self.affiche(arg)).grid(row=1,column=3,padx=2,pady=2)
Button(fram,text='4',font='arial 10 bold',bg='white',relief=FLAT,
command= lambda arg=4: self.affiche(arg)).grid(row=2,column=1,padx=2,pady=2)
Button(fram,text='5',font='arial 10 bold',bg='white',relief=FLAT,
command= lambda arg=5: self.affiche(arg)).grid(row=2,column=2,padx=2,pady=2)
Button(fram,text='6',font='arial 10 bold',bg='white',relief=FLAT,
command= lambda arg=6: self.affiche(arg)).grid(row=2,column=3,padx=2,pady=2)
Button(fram,text='7',font='arial 10 bold',bg='white',relief=FLAT,
command= lambda arg=7: self.affiche(arg)).grid(row=3,column=1,padx=2,pady=2)
Button(fram,text='8',font='arial 10 bold',bg='white',relief=FLAT,
command= lambda arg=8: self.affiche(arg)).grid(row=3,column=2,padx=2,pady=2)
Button(fram,text='9',font='arial 10 bold',bg='white',relief=FLAT,
command= lambda arg=9: self.affiche(arg)).grid(row=3,column=3,padx=2,pady=2)
Button(fram,text='0',font='arial 10 bold',bg='white',relief=FLAT,
command= lambda arg=0: self.affiche(arg)).grid(row=4,column=1,columnspan=3,padx=2,pady=2)
Button(self,text='Quitter',font='arial 10 bold',bg='grey40',relief=FLAT,command=self.quitter).grid(pady=2)
self.can.bind_all('<Key>',self.touche)
self.master.bind('<Escape>',self.quitter) #Pour sortir avec la touche Echap
def quitter(self,event=None):
self.can.delete(ALL)
self.master.destroy()
def affiche(self,arg=None):
self.initialisation()
v=list(code[arg])
for i in v:
self.can.itemconfig(i,fill='red')
def initialisation(self):
for i in self.lst:
self.can.itemconfig(i,fill='black')
def touche(self,event=None):
try: a=int(event.char)
except: pass
else:
self.initialisation()
v=list(code[a])
for i in v:
self.can.itemconfig(i,fill='red')
if __name__=='__main__':
app=Afficheur()
app.mainloop()
Conclusion :
C'est mon premier code.Merci
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.