Accueil > > > ENSSEMBLE DE TROIS WIDGETS AFFICHEURS POUR TKINTER: AFF7SEG, GALVANOMÈTRE ET BAREGRAPH
ENSSEMBLE DE TROIS WIDGETS AFFICHEURS POUR TKINTER: AFF7SEG, GALVANOMÈTRE ET BAREGRAPH
Information sur la source
Description
Regroupe les trois premières sources que j'ai développée avec une modification: Tous les widgets sont dans des classes qu'il suffit d'importer dans votre programme et d'utiliser comme n'importes quels widgets Tkinter.
Source
- # -*- coding: cp1252 -*-
- # Enssemble de 3 types d'afficheurs :
- # Baregraph, Galvanomètre et Afficheur 7 Segments.
- #la consigne est une valeurncomprise entre 0 et 100.
-
- from Tkinter import*
- class segs(Canvas):
- def __init__(self,parent):
- global root,d,u,chiffre,coded,codeu
- root=parent
- 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
- Canvas.__init__(self)
- self.create_rectangle(0,0,200,200,fill="white",outline="white")
- self.create_rectangle(10,30,190,170,width=2,fill="grey")
- self.create_line(100,30,100,170,width=2)
- self.create_line(30,50,80,50,width=5,fill="pink")
- self.create_line(30,100,80,100,width=5,fill="pink")
- self.create_line(30,150,80,150,width=5,fill="pink")
- self.create_line(120,50,170,50,width=5,fill="pink")
- self.create_line(120,100,170,100,width=5,fill="pink")
- self.create_line(120,150,170,150,width=5,fill="pink")
- self.create_line(25,55,25,95,width=5,fill="pink")
- self.create_line(115,55,115,95,width=5,fill="pink")
- self.create_line(85,55,85,95,width=5,fill="pink")
- self.create_line(175,55,175,95,width=5,fill="pink")
- self.create_line(25,105,25,145,width=5,fill="pink")
- self.create_line(115,105,115,145,width=5,fill="pink")
- self.create_line(85,105,85,145,width=5,fill="pink")
- self.create_line(175,105,175,145,width=5,fill="pink")
-
- def SetValue(self,consigne):
- global root,d,u
- self.create_line(30,50,80,50,width=5,fill="pink")
- self.create_line(30,100,80,100,width=5,fill="pink")
- self.create_line(30,150,80,150,width=5,fill="pink")
- self.create_line(120,50,170,50,width=5,fill="pink")
- self.create_line(120,100,170,100,width=5,fill="pink")
- self.create_line(120,150,170,150,width=5,fill="pink")
- self.create_line(25,55,25,95,width=5,fill="pink")
- self.create_line(115,55,115,95,width=5,fill="pink")
- self.create_line(85,55,85,95,width=5,fill="pink")
- self.create_line(175,55,175,95,width=5,fill="pink")
- self.create_line(25,105,25,145,width=5,fill="pink")
- self.create_line(115,105,115,145,width=5,fill="pink")
- self.create_line(85,105,85,145,width=5,fill="pink")
- self.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:
- self.create_line(codeu[i],width=5,fill="red")
-
- for j in segd:
- self.create_line(coded[j],width=5,fill="red")
-
- root.update()
-
- class Galva(Canvas):
- def __init__(self,parent):
- global valeur,root,aiguille,txt
- root=parent
- valeur=0.
- b=0
- a=0
-
- Canvas.__init__(self)
- #Dessin du Galva
- self.create_rectangle(0,0,200,200,fill="white",outline="white")
- self.create_rectangle(10,10,190,150,width=2,fill="white")
- self.create_rectangle(10,120,190,150,width=2,fill="grey")
- self.create_oval(25,25,175,175,width=2)
- self.create_rectangle(12,60,188,118,fill="white",outline="white")
- self.create_rectangle(12,121,188,148,fill="grey",outline="grey")
- self.create_rectangle(10,151,190,200,fill="white",outline="white")
- self.create_oval(90,125,110,145, width=2,fill="white")
- self.create_line(108,127,92,143,width=5)
- self.create_oval(95,100,105,110,fill="red",outline="red")
- a=(3-(0/50.))*(pi/4)
- x=100+90*cos(a)
- y=105-90*sin(a)
- aiguille=self.create_line(100,105,x,y,width=1,fill="red")
- txt=self.create_text(12,160, text="0")
-
- parent.update()
-
- def SetValue(self,consigne):
- global valeur,root,aiguille,txt
- parent=root
-
- while (int(valeur*100+.5)!=int(consigne*100+.5)):
- if (valeur<consigne):
- valeur=valeur+(float(consigne-valeur)/50)
- float (valeur)
- a=(3-(valeur/50.))*(pi/4)
- x=100+90*cos(a)
- y=105-90*sin(a)
- self.delete(aiguille)
- self.delete(txt)
- aiguille=self.create_line(100,105,x,y,width=1,fill="red")
- txt=self.create_text(12,160, text=int(valeur) )
- parent.update()
- time.sleep(0.002) #Définie l'inertie de l'aiguille (Timer)
-
-
- elif(valeur>consigne):
- valeur=valeur+(float(consigne-valeur)/50)
- float (valeur)
- a=(3-(valeur/50.))*(pi/4)
- x=100+90*cos(a)
- y=105-90*sin(a)
- self.delete(aiguille)
- self.delete(txt)
- aiguille=self.create_line(100,105,x,y,width=1,fill="red")
- txt=self.create_text(12,160, text=int(valeur) )
- parent.update()
- time.sleep(0.002) #Définie l'inertie de l'aiguille (Timer)
-
-
- else:
- float (valeur)
- a=(3-(valeur/50.))*(pi/4)
- x=100+90*cos(a)
- y=105-90*sin(a)
- self.delete(aiguille)
- self.delete(txt)
- aiguille=self.create_line(100,105,x,y,width=1,fill="red")
- txt=can.create_text(12,160, text=int(valeur) )
- parent.update()
- time.sleep(0.002) #Définie l'inertie de l'aiguille (Timer)
-
- class Bar(Canvas):
- def __init__(self,parent):
- global i,j,txt
- i,j=25,170
-
- Canvas.__init__(self)
- #Dessin du Galva
- self.create_rectangle(0,0,200,200,fill="white",outline="white")
- self.create_rectangle(60,10,140,190,fill="grey")
- m,j,k,l=25,65,125,175
- consigne=random.randint(0,100)
- txt=self.create_text(10,10,text="0")
- while m<70:
- self.create_line(70,m,130,m,width=5,fill="pink")
- m=m+10
- while m<120:
- self.create_line(70,m,130,m,width=5,fill="yellow")
- m=m+10
- while m<180:
- self.create_line(70,m,130,m,width=5,fill="aquamarine")
- m=m+10
-
- parent.update()
-
- def SetValue(self,consigne):
- global txt
- parent=root
-
- m,j,k,l=25,65,125,175
- self.delete(txt)
- while m<70:
- self.create_line(70,m,130,m,width=5,fill="pink")
- m=m+10
- while m<120:
- self.create_line(70,m,130,m,width=5,fill="yellow")
- m=m+10
- while m<180:
- self.create_line(70,m,130,m,width=5,fill="aquamarine")
- m=m+10
- valeur=int(consigne*0.16)
- txt=self.create_text(10,10,text=consigne)
- while valeur>=12:
- self.create_line(70,j,130,j,width=5,fill="red")
- valeur=valeur-1
- j=j-10
- while valeur>=6:
- self.create_line(70,k,130,k,width=5,fill="orange")
- valeur=valeur-1
- k=k-10
- while valeur>=0:
- self.create_line(70,l,130,l,width=5,fill="green")
- valeur=valeur-1
- l=l-10
- parent.update()
# -*- coding: cp1252 -*-
# Enssemble de 3 types d'afficheurs :
# Baregraph, Galvanomètre et Afficheur 7 Segments.
#la consigne est une valeurncomprise entre 0 et 100.
from Tkinter import*
class segs(Canvas):
def __init__(self,parent):
global root,d,u,chiffre,coded,codeu
root=parent
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
Canvas.__init__(self)
self.create_rectangle(0,0,200,200,fill="white",outline="white")
self.create_rectangle(10,30,190,170,width=2,fill="grey")
self.create_line(100,30,100,170,width=2)
self.create_line(30,50,80,50,width=5,fill="pink")
self.create_line(30,100,80,100,width=5,fill="pink")
self.create_line(30,150,80,150,width=5,fill="pink")
self.create_line(120,50,170,50,width=5,fill="pink")
self.create_line(120,100,170,100,width=5,fill="pink")
self.create_line(120,150,170,150,width=5,fill="pink")
self.create_line(25,55,25,95,width=5,fill="pink")
self.create_line(115,55,115,95,width=5,fill="pink")
self.create_line(85,55,85,95,width=5,fill="pink")
self.create_line(175,55,175,95,width=5,fill="pink")
self.create_line(25,105,25,145,width=5,fill="pink")
self.create_line(115,105,115,145,width=5,fill="pink")
self.create_line(85,105,85,145,width=5,fill="pink")
self.create_line(175,105,175,145,width=5,fill="pink")
def SetValue(self,consigne):
global root,d,u
self.create_line(30,50,80,50,width=5,fill="pink")
self.create_line(30,100,80,100,width=5,fill="pink")
self.create_line(30,150,80,150,width=5,fill="pink")
self.create_line(120,50,170,50,width=5,fill="pink")
self.create_line(120,100,170,100,width=5,fill="pink")
self.create_line(120,150,170,150,width=5,fill="pink")
self.create_line(25,55,25,95,width=5,fill="pink")
self.create_line(115,55,115,95,width=5,fill="pink")
self.create_line(85,55,85,95,width=5,fill="pink")
self.create_line(175,55,175,95,width=5,fill="pink")
self.create_line(25,105,25,145,width=5,fill="pink")
self.create_line(115,105,115,145,width=5,fill="pink")
self.create_line(85,105,85,145,width=5,fill="pink")
self.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:
self.create_line(codeu[i],width=5,fill="red")
for j in segd:
self.create_line(coded[j],width=5,fill="red")
root.update()
class Galva(Canvas):
def __init__(self,parent):
global valeur,root,aiguille,txt
root=parent
valeur=0.
b=0
a=0
Canvas.__init__(self)
#Dessin du Galva
self.create_rectangle(0,0,200,200,fill="white",outline="white")
self.create_rectangle(10,10,190,150,width=2,fill="white")
self.create_rectangle(10,120,190,150,width=2,fill="grey")
self.create_oval(25,25,175,175,width=2)
self.create_rectangle(12,60,188,118,fill="white",outline="white")
self.create_rectangle(12,121,188,148,fill="grey",outline="grey")
self.create_rectangle(10,151,190,200,fill="white",outline="white")
self.create_oval(90,125,110,145, width=2,fill="white")
self.create_line(108,127,92,143,width=5)
self.create_oval(95,100,105,110,fill="red",outline="red")
a=(3-(0/50.))*(pi/4)
x=100+90*cos(a)
y=105-90*sin(a)
aiguille=self.create_line(100,105,x,y,width=1,fill="red")
txt=self.create_text(12,160, text="0")
parent.update()
def SetValue(self,consigne):
global valeur,root,aiguille,txt
parent=root
while (int(valeur*100+.5)!=int(consigne*100+.5)):
if (valeur<consigne):
valeur=valeur+(float(consigne-valeur)/50)
float (valeur)
a=(3-(valeur/50.))*(pi/4)
x=100+90*cos(a)
y=105-90*sin(a)
self.delete(aiguille)
self.delete(txt)
aiguille=self.create_line(100,105,x,y,width=1,fill="red")
txt=self.create_text(12,160, text=int(valeur) )
parent.update()
time.sleep(0.002) #Définie l'inertie de l'aiguille (Timer)
elif(valeur>consigne):
valeur=valeur+(float(consigne-valeur)/50)
float (valeur)
a=(3-(valeur/50.))*(pi/4)
x=100+90*cos(a)
y=105-90*sin(a)
self.delete(aiguille)
self.delete(txt)
aiguille=self.create_line(100,105,x,y,width=1,fill="red")
txt=self.create_text(12,160, text=int(valeur) )
parent.update()
time.sleep(0.002) #Définie l'inertie de l'aiguille (Timer)
else:
float (valeur)
a=(3-(valeur/50.))*(pi/4)
x=100+90*cos(a)
y=105-90*sin(a)
self.delete(aiguille)
self.delete(txt)
aiguille=self.create_line(100,105,x,y,width=1,fill="red")
txt=can.create_text(12,160, text=int(valeur) )
parent.update()
time.sleep(0.002) #Définie l'inertie de l'aiguille (Timer)
class Bar(Canvas):
def __init__(self,parent):
global i,j,txt
i,j=25,170
Canvas.__init__(self)
#Dessin du Galva
self.create_rectangle(0,0,200,200,fill="white",outline="white")
self.create_rectangle(60,10,140,190,fill="grey")
m,j,k,l=25,65,125,175
consigne=random.randint(0,100)
txt=self.create_text(10,10,text="0")
while m<70:
self.create_line(70,m,130,m,width=5,fill="pink")
m=m+10
while m<120:
self.create_line(70,m,130,m,width=5,fill="yellow")
m=m+10
while m<180:
self.create_line(70,m,130,m,width=5,fill="aquamarine")
m=m+10
parent.update()
def SetValue(self,consigne):
global txt
parent=root
m,j,k,l=25,65,125,175
self.delete(txt)
while m<70:
self.create_line(70,m,130,m,width=5,fill="pink")
m=m+10
while m<120:
self.create_line(70,m,130,m,width=5,fill="yellow")
m=m+10
while m<180:
self.create_line(70,m,130,m,width=5,fill="aquamarine")
m=m+10
valeur=int(consigne*0.16)
txt=self.create_text(10,10,text=consigne)
while valeur>=12:
self.create_line(70,j,130,j,width=5,fill="red")
valeur=valeur-1
j=j-10
while valeur>=6:
self.create_line(70,k,130,k,width=5,fill="orange")
valeur=valeur-1
k=k-10
while valeur>=0:
self.create_line(70,l,130,l,width=5,fill="green")
valeur=valeur-1
l=l-10
parent.update()
Conclusion
En espérant qu'ils puissent servir à quelqu'un...
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
[MIX10] KEYNOTE DEUXIèME JOURNéE - INTERNET EXPLORER 9, HTML5, VISUAL STUDIO 2010, ODATA[MIX10] KEYNOTE DEUXIèME JOURNéE - INTERNET EXPLORER 9, HTML5, VISUAL STUDIO 2010, ODATA par cyril
Le deuxième keynote du mix fut très riche en contenu. Internet Explorer 9 Juste un après le lancement de Internet Explorer 8, Microsoft a dévoilé les nouveautés de Internet Explorer 9. Désormais, IE supportera HTML5, SVG et CSS3. L'élément ...
Cliquez pour lire la suite de l'article par cyril CERTIFICATIONS BETA .NET 4CERTIFICATIONS BETA .NET 4 par KooKiz
Les inscriptions pour les certifications beta .NET 4 ont commencé. L'inscription est offerte pour les examens suivants : - 71-511, TS: Windows Applications Development with Microsoft .NET Framework 4 - 71-515, TS: Web Applications Development with...
Cliquez pour lire la suite de l'article par KooKiz [MIX 2010] - MICROSOFT TRANSLATOR TECHNOLOGY PREVIEW V2[MIX 2010] - MICROSOFT TRANSLATOR TECHNOLOGY PREVIEW V2 par redo
J'imagine que la plupart d'entre vous connaissent bien et utilisent le service de traduction de Google, mais connaissez-vous celui de Microsoft . Microsoft Translator ? Effectivement, Microsoft nous annoncé le lancement version 2 de la Technologie Preview...
Cliquez pour lire la suite de l'article par redo LANCEMENT EN PREVIEW DE CYCLONE LORS DES TECHDAYS 2010!LANCEMENT EN PREVIEW DE CYCLONE LORS DES TECHDAYS 2010! par MPOWARE
Toutes les vidéos de ce lancement sont en ligne!
Partie I - Intro
http://www.youtube.com/watch?v=LkQzTQ8T6CA
Partie II - Démo 1
http://www.youtube.com/watch?v=drAhYQ7lqvo
Partie III - Démo 2
http://www.youtube.com/watch?v=c8KM_1Gqybc...
Cliquez pour lire la suite de l'article par MPOWARE [WP7] JE NE VEUX PAS D'UN NOUVEL IPHONE[WP7] JE NE VEUX PAS D'UN NOUVEL IPHONE par FREMYCOMPANY
Je pense qu'ils ont besoin d'une piqure de rappel chez Microsoft : c'est bien gentil d'avoir une interface jolie, mais si c'est pour avoir un truc qui ne convainct pas dedans, c'est peine perdue.
---->
Système ouvert ----> Fermé ?
P...
Cliquez pour lire la suite de l'article par FREMYCOMPANY
Logiciels
Xilisoft Convertisseur Vidéo Ultimate (5.1.39.0305)XILISOFT CONVERTISSEUR VIDéO ULTIMATE (5.1.39.0305)Xilisoft Convertisseur Vidéo Ultimate est un outil puissant de conversion vidéo, facile à utilise... Cliquez pour télécharger Xilisoft Convertisseur Vidéo Ultimate Xilisoft DVD Ripper Ultimate (5.0.64.0304)XILISOFT DVD RIPPER ULTIMATE (5.0.64.0304)Xilisoft DVD Ripper Ultimate est un logiciel excellent pour copier et convertir DVD vers presque ... Cliquez pour télécharger Xilisoft DVD Ripper Ultimate Rigs of Rods (63.3)RIGS OF RODS (63.3)c'est un jeu de multi-simulation camions,autobus voitures, avions, bateaux, hélicoptère avec défo... Cliquez pour télécharger Rigs of Rods Konvertor (4.00)KONVERTOR (4.00)Le logiciel est un gestionnaire multimedia affichant, jouant et convertissant plus de 2000 format... Cliquez pour télécharger Konvertor
|