Accueil > Forum > > > > Problème de définition
Problème de définition
jeudi 12 juin 2008 à 20:44:22 |
Problème de définition

amaury74
|
Bonjours à tous, J'ai écrit plusieurs petit codes destinés à dessiner des afficheurs sur Tkinter. J'ai définie une fonction pour chaque code avec la commande def à l'intérieur d'un code plus important. Le problème est que lorsque j'appelle l'une des fonction précédement crées, rien ne se passe. Les fonctions onSelect marchent, mais pas onGalva, OnAff et OnLed... Voici l'intégralité de mon code (un peu long): # -*- coding: cp1252 -*- from Tkinter import * from math import * import time import random select1=0 select2=0 select3=0 select4=0 select11=0 select12=0 select13=0 select14=0 consigne1=0 consigne2=0 consigne3=0 consigne4=0 #--------------------------------------------------------------------------------------------------------------------------- def onGalva (can,consigne): valeur=0. can.create_rectangle(0,0,200,200,fill="white",outline="white") can.create_rectangle(10,10,190,150,width=2,fill="white") can.create_rectangle(10,120,190,150,width=2,fill="grey") can.create_oval(25,25,175,175,width=2) can.create_rectangle(12,60,188,118,fill="white",outline="white") can.create_rectangle(12,121,188,148,fill="grey",outline="grey") can.create_rectangle(10,151,190,200,fill="white",outline="white") can.create_oval(90,125,110,145, width=2,fill="white") can.create_line(108,127,92,143,width=5) can.create_oval(95,100,105,110,fill="red",outline="red") #Comportement linéaire 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) aiguille=can.create_line(100,105,x,y,width=1,fill="red") root.update() time.sleep(0.002) #Définie l'inertie de l'aiguille (Timer) can.delete(aiguille) 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) aiguille=can.create_line(100,105,x,y,width=1,fill="red") root.update() time.sleep(0.002) #Définie l'inertie de l'aiguille (Timer) can.delete(aiguille) else: float (valeur) a=(3-(valeur/50.))*(pi/4) x=100+90*cos(a) y=105-90*sin(a) aiguille=can1.create_line(100,105,x,y,width=1,fill="red") root.update() time.sleep(0.002) #Définie l'inertie de l'aiguille (Timer) can.delete(aiguille) can.update() #--------------------------------------------------------------------------------------------------------------------------- def onAff (can,consigne): 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 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) d=0 u=0 # 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") #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") can.update() #--------------------------------------------------------------------------------------------------------------------------- def onLed(can4,consigne): i,j=25,170 can4.create_rectangle(0,0,200,200,fill="white",outline="white") can4.create_rectangle(60,10,140,190,fill="grey") m,j,k,l=25,65,125,175 consigne4=random.randint(0,100) while m<70: can4.create_line(70,m,130,m,width=5,fill="pink") m=m+10 while m<120: can4.create_line(70,m,130,m,width=5,fill="yellow") m=m+10 while m<180: can4.create_line(70,m,130,m,width=5,fill="aquamarine") m=m+10 valeur4=int(consigne4*0.16) while valeur4>=12: can4.create_line(70,j,130,j,width=5,fill="red") valeur4=valeur4-1 j=j-10 while valeur4>=6: can4.create_line(70,k,130,k,width=5,fill="orange") valeur4=valeur4-1 k=k-10 while valeur4>=0: can4.create_line(70,l,130,l,width=5,fill="green") valeur4=valeur4-1 l=l-10 can.update() #--------------------------------------------------------------------------------------------------------------------------- def onSelect1(e): select1=lst1.get(lst1.curselection()) lab1.configure(text=select1) def onSelect2(e): select2=lst2.get(lst2.curselection()) lab2.configure(text=select2) def onSelect3(e): select3=lst3.get(lst3.curselection()) lab3.configure(text=select3) def onSelect4(e): select4=lst4.get(lst4.curselection()) lab4.configure(text=select4) def onSelect11(e): select11=lst11.get(lst11.curselection()) lab11.configure(text=select11) def onSelect12(e): select12=lst12.get(lst12.curselection()) lab12.configure(text=select12) def onSelect13(e): select13=lst13.get(lst13.curselection()) lab13.configure(text=select13) def onSelect14(e): select14=lst14.get(lst14.curselection()) lab14.configure(text=select14) #--------------------------------------------------------------------------------------------------------------------------- root=Tk() can1=Canvas(width=200,height=200,bg="white") can2=Canvas(width=200,height=200,bg="white") can3=Canvas(width=200,height=200,bg="white") can4=Canvas(width=200,height=200,bg="white") lst1=Listbox(root) lab1=Label(root,text="_") lst1.grid(row=0,column=1) lab1.grid(row=1,column=1) #--------------------------------------------------------------------------------------------------------------------------- for grandeur in ['% CPU1' , '% CPU2', '% CPU3', '% CPU4', '% RAM' , "% GPU1" , "% GPU2" , "% GPU3" , "T cpu" , "T gpu1" , "T gpu2" , "T gpu3" , "T chipset"]: lst1.insert(END,grandeur) lst1.bind('<Double-1>',onSelect1) lst2=Listbox(root) lab2=Label(root,text="_") lst2.grid(row=0,column=4) lab2.grid(row=1,column=4) for grandeur in ['% CPU1' , '% CPU2', '% CPU3', '% CPU4', '% RAM' , "% GPU1" , "% GPU2" , "% GPU3" , "T cpu" , "T gpu1" , "T gpu2" , "T gpu3" , "T chipset"]: lst2.insert(END,grandeur) lst2.bind('<Double-1>',onSelect2) lst3=Listbox(root) lab3=Label(root,text="_") lst3.grid(row=2,column=1) lab3.grid(row=3,column=1) for grandeur in ['% CPU1' , '% CPU2', '% CPU3', '% CPU4', '% RAM' , "% GPU1" , "% GPU2" , "% GPU3" , "T cpu" , "T gpu1" , "T gpu2" , "T gpu3" , "T chipset"]: lst3.insert(END,grandeur) lst3.bind('<Double-1>',onSelect3) lst4=Listbox(root) lab4=Label(root,text="_") lst4.grid(row=2,column=4) lab4.grid(row=3,column=5) for grandeur in ['% CPU1' , '% CPU2', '% CPU3', '% CPU4', '% RAM' , "% GPU1" , "% GPU2" , "% GPU3" , "T cpu" , "T gpu1" , "T gpu2" , "T gpu3" , "T chipset"]: lst4.insert(END,grandeur) lst4.bind('<Double-1>',onSelect4) #--------------------------------------------------------------------------------------------------------------------------- lst11=Listbox(root) lab11=Label(root,text="_") lst11.grid(row=0,column=2) lab11.grid(row=1,column=2) for grandeur in ["Galva","Aff7seg","LEDS"]: lst11.insert(END,grandeur) lst11.bind('<Double-1>',onSelect11) lst12=Listbox(root) lab12=Label(root,text="_") lst12.grid(row=0,column=5) lab12.grid(row=1,column=5) for grandeur in ["Galva","Aff7seg","LEDS"]: lst12.insert(END,grandeur) lst12.bind('<Double-1>',onSelect12) lst13=Listbox(root) lab13=Label(root,text="_") lst13.grid(row=2,column=2) lab13.grid(row=3,column=2) for grandeur in ["Galva","Aff7seg","LEDS"]: lst13.insert(END,grandeur) lst13.bind('<Double-1>',onSelect13) lst14=Listbox(root) lab14=Label(root,text="_") lst14.grid(row=2,column=5) lab14.grid(row=3,column=5) for grandeur in ["Galva","Aff7seg","LEDS"]: lst14.insert(END,grandeur) lst14.bind('<Double-1>',onSelect14) #--------------------------------------------------------------------------------------------------------------------------- while 1: consigne1=random.randint(0,99) consigne2=random.randint(0,99) consigne3=random.randint(0,99) consigne4=random.randint(0,99) can1.grid(row=0,column=0) can2.grid(row=2,column=0) can3.grid(row=0,column=3) can4.grid(row=2,column=3) #--------------------------------------------------------------------------------------------------------------------------- if (select11=="Galva"): can1.delete(ALL) onGalva(can1,consigne1) elif (select11=="Aff7seg"): can1.delete(ALL) onAff(can1,consigne1) elif (select11=="LEDS"): can1.delete(ALL) onLed(can1,consigne1) else: can1.delete(ALL) can1.create_text(100,100,text="Aucun") #--------------------------------------------------------------------------------------------------------------------------- if (select12=="Galva"): can2.delete(ALL) onGalva(can2,consigne2) elif (select12=="Aff7seg"): can2.delete(ALL) onAff(can2,consigne2) elif (select12=="LEDS"): can2.delete(ALL) onLed(can2,consigne2) else: can2.delete(ALL) can2.create_text(100,100,text="Aucun") #--------------------------------------------------------------------------------------------------------------------------- if (select13=="Galva"): can3.delete(ALL) onGalva(can3,consigne3) elif (select13=="Aff7seg"): can3.delete(ALL) onAff(can3,consigne3) elif (select11=="LEDS"): can3.delete(ALL) onLed(can3,consigne3) else: can3.delete(ALL) can3.create_text(100,100,text="Aucun") #--------------------------------------------------------------------------------------------------------------------------- if (select14=="Galva"): can4.delete(ALL) onGalva(can4,consigne4) elif (select14=="Aff7seg"): can4.delete(ALL) onAff(can4,consigne4) elif (select14=="LEDS"): can4.delete(ALL) onLed(can4,consigne4) else: can4.delete(ALL) can4.create_text(100,100,text="Aucun") root.update()
|
|
vendredi 13 juin 2008 à 10:11:13 |
Re : Problème de définition

aera group
|
aie aie aie .... Essayerais tu de remplacer Windows ? Tu as créé une boucle infini (while 1) pour "surveiller" les choix de l'utilisateur ; Résultat, mon UC est monter à 65% d'utilisation et rien ne se passe. Tout ton programme est absorbé par ta boucle, et Python aussi si bien qu'il n'arrive pas à te signaller les erreurs dans tes fonction (fonction onLed, dernière ligne, ne serraisse pas can4 par hazar parce que la variable can n'existe pas dans cette fonction). Inutile de vérifier l'état des variables continuallement, elles ne peuvent changer que lorsqu'un événement sur les listes de sélection est détecté (heureusement Windows le fait pour nous !). Au passage, j'ai viens de vérifié dans toutes tes sources, mais il manque toujours quelque chose à la fin de tes codes, l'instruction pour que Tk détecte et gère les événements : mainloop() !
Deuxième point important : les variables globales et locales ! Tel que tu l'as écrit ton programme créé deux fois les variables select1, select2, ... une fois globalement (dans les premières lignes du programme !) et une fois localement (dans les fonctions onSelect13, onSelect13, ... Utilise global pour ne plus avoir ce genre de problèmes !
Je t'ai corrigé ton code, tu véras qu'il reste des erreurs, mais j'ai répondu à ta question, et je te laisse un peu de travail ! Bon courrage
# -*- coding: cp1252 -*- from Tkinter import * from math import * import time import random select1=0 select2=0 select3=0 select4=0 select11=0 select12=0 select13=0 select14=0 consigne1=0 consigne2=0 consigne3=0 consigne4=0 #------------------------------------------------------------------------- def onGalva (can,consigne): valeur=0. can.create_rectangle(0,0,200,200,fill="white",outline="white") can.create_rectangle(10,10,190,150,width=2,fill="white") can.create_rectangle(10,120,190,150,width=2,fill="grey") can.create_oval(25,25,175,175,width=2) can.create_rectangle(12,60,188,118,fill="white",outline="white") can.create_rectangle(12,121,188,148,fill="grey",outline="grey") can.create_rectangle(10,151,190,200,fill="white",outline="white") can.create_oval(90,125,110,145, width=2,fill="white") can.create_line(108,127,92,143,width=5) can.create_oval(95,100,105,110,fill="red",outline="red") #Comportement linéaire 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) aiguille=can.create_line(100,105,x,y,width=1,fill="red") root.update() time.sleep(0.002) #Définie l'inertie de l'aiguille (Timer) can.delete(aiguille) 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) aiguille=can.create_line(100,105,x,y,width=1,fill="red") root.update() time.sleep(0.002) #Définie l'inertie de l'aiguille (Timer) can.delete(aiguille) else: float (valeur) a=(3-(valeur/50.))*(pi/4) x=100+90*cos(a) y=105-90*sin(a) aiguille=can1.create_line(100,105,x,y,width=1,fill="red") root.update() time.sleep(0.002) #Définie l'inertie de l'aiguille (Timer) can.delete(aiguille) can.update() #------------------------------------------------------------------------- def onAff (can,consigne): 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 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) d=0 u=0 # 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") #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") can.update() #------------------------------------------------------------------------- def onLed(can4,consigne): i,j=25,170 can4.create_rectangle(0,0,200,200,fill="white",outline="white") can4.create_rectangle(60,10,140,190,fill="grey") m,j,k,l=25,65,125,175 consigne4=random.randint(0,100) while m<70: can4.create_line(70,m,130,m,width=5,fill="pink") m=m+10 while m<120: can4.create_line(70,m,130,m,width=5,fill="yellow") m=m+10 while m<180: can4.create_line(70,m,130,m,width=5,fill="aquamarine") m=m+10 valeur4=int(consigne4*0.16) while valeur4>=12: can4.create_line(70,j,130,j,width=5,fill="red") valeur4=valeur4-1 j=j-10 while valeur4>=6: can4.create_line(70,k,130,k,width=5,fill="orange") valeur4=valeur4-1 k=k-10 while valeur4>=0: can4.create_line(70,l,130,l,width=5,fill="green") valeur4=valeur4-1 l=l-10 can4.update() #------------------------------------------------------------------------- def onSelect1(e): global select1 select1=lst1.get(int(lst1.curselection()[0])) lab1.configure(text=select1) test() def onSelect2(e): global select2 select2=lst2.get(int(lst2.curselection()[0])) lab2.configure(text=select2) test() def onSelect3(e): global select3 select3=lst3.get(int(lst3.curselection()[0])) lab3.configure(text=select3) test() def onSelect4(e): global select4 select4=lst4.get(int(lst4.curselection()[0])) lab4.configure(text=select4) test() def onSelect11(e): global select11 select11=lst11.get(int(lst11.curselection()[0])) lab11.configure(text=select11) test() def onSelect12(e): global select12 select12=lst12.get(int(lst12.curselection()[0])) lab12.configure(text=select12) test() def onSelect13(e): global select13 select13=lst13.get(int(lst13.curselection()[0])) lab13.configure(text=select13) test() def onSelect14(e): global select14 select14=lst14.get(int(lst14.curselection()[0])) lab14.configure(text=select14) test() def test(): global select1,select2,select3,select4,select11,select12,select13,select14 consigne1=random.randint(0,99) consigne2=random.randint(0,99) consigne3=random.randint(0,99) consigne4=random.randint(0,99) #--------------------------------------------------------------------- if (select11=="Galva"): can1.delete(ALL) onGalva(can1,consigne1) elif (select11=="Aff7seg"): can1.delete(ALL) onAff(can1,consigne1) elif (select11=="LEDS"): can1.delete(ALL) onLed(can1,consigne1) else: can1.delete(ALL) can1.create_text(100,100,text="Aucun") #--------------------------------------------------------------------- if (select12=="Galva"): can2.delete(ALL) onGalva(can2,consigne2) elif (select12=="Aff7seg"): can2.delete(ALL) onAff(can2,consigne2) elif (select12=="LEDS"): can2.delete(ALL) onLed(can2,consigne2) else: can2.delete(ALL) can2.create_text(100,100,text="Aucun") #------------------------------------------------------------------- if (select13=="Galva"): can3.delete(ALL) onGalva(can3,consigne3) elif (select13=="Aff7seg"): can3.delete(ALL) onAff(can3,consigne3) elif (select11=="LEDS"): can3.delete(ALL) onLed(can3,consigne3) else: can3.delete(ALL) can3.create_text(100,100,text="Aucun") #--------------------------------------------------------------------- if (select14=="Galva"): can4.delete(ALL) onGalva(can4,consigne4) elif (select14=="Aff7seg"): can4.delete(ALL) onAff(can4,consigne4) elif (select14=="LEDS"): can4.delete(ALL) onLed(can4,consigne4) else: can4.delete(ALL) can4.create_text(100,100,text="Aucun") root.update() #------------------------------------------------------------------------- root=Tk() can1=Canvas(width=200,height=200,bg="white") can2=Canvas(width=200,height=200,bg="white") can3=Canvas(width=200,height=200,bg="white") can4=Canvas(width=200,height=200,bg="white") lst1=Listbox(root) lab1=Label(root,text="_") lst1.grid(row=0,column=1) lab1.grid(row=1,column=1) #------------------------------------------------------------------------- for grandeur in ['% CPU1' , '% CPU2', '% CPU3', '% CPU4', '% RAM' , "% GPU1" , "% GPU2" , "% GPU3" , "T cpu" , "T gpu1" , "T gpu2" , "T gpu3" , "T chipset"]: lst1.insert(END,grandeur) lst1.bind('<Double-1>',onSelect1) lst2=Listbox(root) lab2=Label(root,text="_") lst2.grid(row=0,column=4) lab2.grid(row=1,column=4) for grandeur in ['% CPU1' , '% CPU2', '% CPU3', '% CPU4', '% RAM' , "% GPU1" , "% GPU2" , "% GPU3" , "T cpu" , "T gpu1" , "T gpu2" , "T gpu3" , "T chipset"]: lst2.insert(END,grandeur) lst2.bind('<Double-1>',onSelect2) lst3=Listbox(root) lab3=Label(root,text="_") lst3.grid(row=2,column=1) lab3.grid(row=3,column=1) for grandeur in ['% CPU1' , '% CPU2', '% CPU3', '% CPU4', '% RAM' , "% GPU1" , "% GPU2" , "% GPU3" , "T cpu" , "T gpu1" , "T gpu2" , "T gpu3" , "T chipset"]: lst3.insert(END,grandeur) lst3.bind('<Double-1>',onSelect3) lst4=Listbox(root) lab4=Label(root,text="_") lst4.grid(row=2,column=4) lab4.grid(row=3,column=5) for grandeur in ['% CPU1' , '% CPU2', '% CPU3', '% CPU4', '% RAM' , "% GPU1" , "% GPU2" , "% GPU3" , "T cpu" , "T gpu1" , "T gpu2" , "T gpu3" , "T chipset"]: lst4.insert(END,grandeur) lst4.bind('<Double-1>',onSelect4) #------------------------------------------------------------------------- lst11=Listbox(root) lab11=Label(root,text="_") lst11.grid(row=0,column=2) lab11.grid(row=1,column=2) for grandeur in ["Galva","Aff7seg","LEDS"]: lst11.insert(END,grandeur) lst11.bind('<Double-1>',onSelect11) lst12=Listbox(root) lab12=Label(root,text="_") lst12.grid(row=0,column=5) lab12.grid(row=1,column=5) for grandeur in ["Galva","Aff7seg","LEDS"]: lst12.insert(END,grandeur) lst12.bind('<Double-1>',onSelect12) lst13=Listbox(root) lab13=Label(root,text="_") lst13.grid(row=2,column=2) lab13.grid(row=3,column=2) for grandeur in ["Galva","Aff7seg","LEDS"]: lst13.insert(END,grandeur) lst13.bind('<Double-1>',onSelect13) lst14=Listbox(root) lab14=Label(root,text="_") lst14.grid(row=2,column=5) lab14.grid(row=3,column=5) for grandeur in ["Galva","Aff7seg","LEDS"]: lst14.insert(END,grandeur) lst14.bind('<Double-1>',onSelect14) can1.grid(row=0,column=0) can2.grid(row=2,column=0) can3.grid(row=0,column=3) can4.grid(row=2,column=3) #--------------------------------------------------------------------------------------------------------------------------- root.mainloop() # démarrage du réceptionnaire d'événements ______ Aéra
|
|
vendredi 13 juin 2008 à 11:31:20 |
Re : Problème de définition

amaury74
|
Merci pour ces réponses claires. Il est quasiment impossible de trouver sur internet des informations claires et en français sur Python...
|
|
vendredi 13 juin 2008 à 11:36:29 |
Re : Problème de définition
|
samedi 14 juin 2008 à 11:16:05 |
Re : Problème de définition

amaury74
|
Merci pour le PDF, mais je le connais déja. J'ai pas du lire assez loin...
;)
|
|
lundi 16 juin 2008 à 15:10:08 |
Re : Problème de définition

amaury74
|
Le code débeuguer, si quelqu'un est intéressé:
# -*- coding: cp1252 -*- from Tkinter import * from math import * import time import random select1=0 select2=0 select3=0 select4=0 select11=0 select12=0 select13=0 select14=0 consigne1=0 consigne2=0 consigne3=0 consigne4=0 #------------------------------------------------------------------------- def onGalva (can,consigne,valeur): can.create_rectangle(0,0,200,200,fill="white",outline="white") can.create_rectangle(10,10,190,150,width=2,fill="white") can.create_rectangle(10,120,190,150,width=2,fill="grey") can.create_oval(25,25,175,175,width=2) can.create_rectangle(12,60,188,118,fill="white",outline="white") can.create_rectangle(12,121,188,148,fill="grey",outline="grey") can.create_rectangle(10,151,190,200,fill="white",outline="white") can.create_oval(90,125,110,145, width=2,fill="white") can.create_line(108,127,92,143,width=5) can.create_oval(95,100,105,110,fill="red",outline="red") b=(3-(valeur/50.))*(pi/4) e=100+90*cos(b) f=105-90*sin(b) aiguille=can.create_line(100,105,e,f,width=1,fill="red") #Comportement linéaire while (int(valeur*100+.5)!=int(consigne*100+.5)): if (valeur<consigne): can.delete(aiguille) valeur=valeur+(float(consigne-valeur)/50) float (valeur) a=(3-(valeur/50.))*(pi/4) x=100+90*cos(a) y=105-90*sin(a) aiguille=can.create_line(100,105,x,y,width=1,fill="red") root.update() time.sleep(0.002) #Définie l'inertie de l'aiguille (Timer) elif(valeur>consigne): can.delete(aiguille) valeur=valeur+(float(consigne-valeur)/50) float (valeur) a=(3-(valeur/50.))*(pi/4) x=100+90*cos(a) y=105-90*sin(a) aiguille=can.create_line(100,105,x,y,width=1,fill="red") root.update() time.sleep(0.002) #Définie l'inertie de l'aiguille (Timer) else: can.delete(aiguille) float (valeur) a=(3-(valeur/50.))*(pi/4) x=100+90*cos(a) y=105-90*sin(a) aiguille=can1.create_line(100,105,x,y,width=1,fill="red") root.update() time.sleep(0.002) #Définie l'inertie de l'aiguille (Timer) can.update() return ([x,y,consigne]) #------------------------------------------------------------------------- def onAff (can,consigne): 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 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) d=0 u=0 # 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") #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") can.update() #------------------------------------------------------------------------- def onLed(can4,consigne): i,j=25,170 can4.create_rectangle(0,0,200,200,fill="white",outline="white") can4.create_rectangle(60,10,140,190,fill="grey") m,j,k,l=25,65,125,175 consigne4=random.randint(0,100) while m<70: can4.create_line(70,m,130,m,width=5,fill="pink") m=m+10 while m<120: can4.create_line(70,m,130,m,width=5,fill="yellow") m=m+10 while m<180: can4.create_line(70,m,130,m,width=5,fill="aquamarine") m=m+10 valeur4=int(consigne4*0.16) while valeur4>=12: can4.create_line(70,j,130,j,width=5,fill="red") valeur4=valeur4-1 j=j-10 while valeur4>=6: can4.create_line(70,k,130,k,width=5,fill="orange") valeur4=valeur4-1 k=k-10 while valeur4>=0: can4.create_line(70,l,130,l,width=5,fill="green") valeur4=valeur4-1 l=l-10 can4.update() #------------------------------------------------------------------------- def onSelect1(e): global select1 select1=lst1.get(int(lst1.curselection()[0])) lab1.configure(text=select1) test() def onSelect2(e): global select2 select2=lst2.get(int(lst2.curselection()[0])) lab2.configure(text=select2) test() def onSelect3(e): global select3 select3=lst3.get(int(lst3.curselection()[0])) lab3.configure(text=select3) test() def onSelect4(e): global select4 select4=lst4.get(int(lst4.curselection()[0])) lab4.configure(text=select4) test() def onSelect11(e): global select11 select11=lst11.get(int(lst11.curselection()[0])) lab11.configure(text=select11) test() def onSelect12(e): global select12 select12=lst12.get(int(lst12.curselection()[0])) lab12.configure(text=select12) test() def onSelect13(e): global select13 select13=lst13.get(int(lst13.curselection()[0])) lab13.configure(text=select13) test() def onSelect14(e): global select14 select14=lst14.get(int(lst14.curselection()[0])) lab14.configure(text=select14) test() def test(): global select1,select2,select3,select4,select11,select12,select13,select14,module1,module2,module3,module4 consigne1=random.randint(0,99) consigne2=random.randint(0,99) consigne3=random.randint(0,99) consigne4=random.randint(0,99) #--------------------------------------------------------------------- if (select11=="Galva"): can1.delete(ALL) try: old1=module1[2] except NameError: old1=0 module1=onGalva(can1,consigne1,old1) elif (select11=="Aff7seg"): can1.delete(ALL) onAff(can1,consigne1) elif (select11=="LEDS"): can1.delete(ALL) onLed(can1,consigne1) else: can1.delete(ALL) can1.create_text(100,100,text="Aucun") #--------------------------------------------------------------------- if (select13=="Galva"): can2.delete(ALL) try: old2=module2[2] except NameError: old2=0 module2=onGalva(can2,consigne2,old2) elif (select13=="Aff7seg"): can2.delete(ALL) onAff(can2,consigne2) elif (select13=="LEDS"): can2.delete(ALL) onLed(can2,consigne2) else: can2.delete(ALL) can2.create_text(100,100,text="Aucun") #------------------------------------------------------------------- if (select12=="Galva"): can3.delete(ALL) try: old3=module3[2] except NameError: old3=0 module3=onGalva(can3,consigne3,old3) elif (select12=="Aff7seg"): can3.delete(ALL) onAff(can3,consigne3) elif (select12=="LEDS"): can3.delete(ALL) onLed(can3,consigne3) else: can3.delete(ALL) can3.create_text(100,100,text="Aucun") #--------------------------------------------------------------------- if (select14=="Galva"): can4.delete(ALL) try: old4=module4[2] except NameError: old4=0 module4=onGalva(can4,consigne4,old4) elif (select14=="Aff7seg"): can4.delete(ALL) onAff(can4,consigne4) elif (select14=="LEDS"): can4.delete(ALL) onLed(can4,consigne4) else: can4.delete(ALL) can4.create_text(100,100,text="Aucun") root.update() #------------------------------------------------------------------------- root=Tk() can1=Canvas(width=200,height=200,bg="white") can2=Canvas(width=200,height=200,bg="white") can3=Canvas(width=200,height=200,bg="white") can4=Canvas(width=200,height=200,bg="white") bou1=Button(root,text="Quitter",command=root.quit) bou2=Button(root,text="Rafraichir",command=test) lst1=Listbox(root) lab1=Label(root,text="_") lst1.grid(row=0,column=1) lab1.grid(row=1,column=1) #------------------------------------------------------------------------- for grandeur in ['% CPU1' , '% CPU2', '% CPU3', '% CPU4', '% RAM' , "% GPU1" , "% GPU2" , "% GPU3" , "T cpu" , "T gpu1" , "T gpu2" , "T gpu3" , "T chipset"]: lst1.insert(END,grandeur) lst1.bind('<Double-1>',onSelect1) lst2=Listbox(root) lab2=Label(root,text="_") lst2.grid(row=0,column=4) lab2.grid(row=1,column=4) for grandeur in ['% CPU1' , '% CPU2', '% CPU3', '% CPU4', '% RAM' , "% GPU1" , "% GPU2" , "% GPU3" , "T cpu" , "T gpu1" , "T gpu2" , "T gpu3" , "T chipset"]: lst2.insert(END,grandeur) lst2.bind('<Double-1>',onSelect2) lst3=Listbox(root) lab3=Label(root,text="_") lst3.grid(row=2,column=1) lab3.grid(row=3,column=1) for grandeur in ['% CPU1' , '% CPU2', '% CPU3', '% CPU4', '% RAM' , "% GPU1" , "% GPU2" , "% GPU3" , "T cpu" , "T gpu1" , "T gpu2" , "T gpu3" , "T chipset"]: lst3.insert(END,grandeur) lst3.bind('<Double-1>',onSelect3) lst4=Listbox(root) lab4=Label(root,text="_") lst4.grid(row=2,column=4) lab4.grid(row=3,column=5) for grandeur in ['% CPU1' , '% CPU2', '% CPU3', '% CPU4', '% RAM' , "% GPU1" , "% GPU2" , "% GPU3" , "T cpu" , "T gpu1" , "T gpu2" , "T gpu3" , "T chipset"]: lst4.insert(END,grandeur) lst4.bind('<Double-1>',onSelect4) #------------------------------------------------------------------------- lst11=Listbox(root) lab11=Label(root,text="_") lst11.grid(row=0,column=2) lab11.grid(row=1,column=2) for grandeur in ["Galva","Aff7seg","LEDS"]: lst11.insert(END,grandeur) lst11.bind('<Double-1>',onSelect11) lst12=Listbox(root) lab12=Label(root,text="_") lst12.grid(row=0,column=5) lab12.grid(row=1,column=5) for grandeur in ["Galva","Aff7seg","LEDS"]: lst12.insert(END,grandeur) lst12.bind('<Double-1>',onSelect12) lst13=Listbox(root) lab13=Label(root,text="_") lst13.grid(row=2,column=2) lab13.grid(row=3,column=2) for grandeur in ["Galva","Aff7seg","LEDS"]: lst13.insert(END,grandeur) lst13.bind('<Double-1>',onSelect13) lst14=Listbox(root) lab14=Label(root,text="_") lst14.grid(row=2,column=5) lab14.grid(row=3,column=5) for grandeur in ["Galva","Aff7seg","LEDS"]: lst14.insert(END,grandeur) lst14.bind('<Double-1>',onSelect14) can1.grid(row=0,column=0) can2.grid(row=2,column=0) can3.grid(row=0,column=3) can4.grid(row=2,column=3) bou1.grid(row=4,column=5) bou2.grid(row=4,column=0) #-------------------------------------------------------------------------------------------------------------------------- root.mainloop() # démarrage du réceptionnaire d'événements
|
|
mercredi 18 juin 2008 à 19:46:12 |
Re : Problème de définition

amaury74
|
Mon code à un peu changé, mais j'ai toujours un problème de définition. Cette fois-ci, c'est lorsque je clique sur le bouton "Tester". J'obtient ce message: Exception in Tkinter callback Traceback (most recent call last): File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__ return self.func(*args) File "F:\prog monitoring\GUI.py", line 203, in onTester module1=onGalva(can1,consigne1,old1) File "F:\prog monitoring\GUI.py", line 59, in onGalva while (int(valeur*100+.5)!=int(consigne*100+.5)): TypeError: unsupported operand type(s) for *: 'instance' and 'int'
Voici mon code:
# -*- coding: cp1252 -*- from Tkinter import * from math import * import time import random select1=0 select2=0 select3=0 select4=0 consigne1=0 consigne2=0 consigne3=0 consigne4=0 try: obFichier = open ("config.txt", "r" ) save1=obFichier.read(8) save2=obFichier.read(8) save3=obFichier.read(8) save4=obFichier.read(8) save11=obFichier.read(8) save12=obFichier.read(8) save13=obFichier.read(8) save14=obFichier.read(8) obFichier.close() except IOError: save1="Aucun" save2="Aucun" save3="Aucun" save4="Aucun" save11="Aucun" save12="Aucun" save13="Aucun" save14="Aucun" obFichier=open("config.txt","w") obFichier.close() #------------------------------------------------------------------------- def onGalva (can,consigne,valeur): can.create_rectangle(0,0,200,200,fill="white",outline="white") can.create_rectangle(10,10,190,150,width=2,fill="white") can.create_rectangle(10,120,190,150,width=2,fill="grey") can.create_oval(25,25,175,175,width=2) can.create_rectangle(12,60,188,118,fill="white",outline="white") can.create_rectangle(12,121,188,148,fill="grey",outline="grey") can.create_rectangle(10,151,190,200,fill="white",outline="white") can.create_oval(90,125,110,145, width=2,fill="white") can.create_line(108,127,92,143,width=5) can.create_oval(95,100,105,110,fill="red",outline="red") b=(3-(valeur/50.))*(pi/4) e=100+90*cos(b) f=105-90*sin(b) aiguille=can.create_line(100,105,e,f,width=1,fill="red") #Comportement linéaire while (int(valeur*100+.5)!=int(consigne*100+.5)): if (valeur<consigne): can.delete(aiguille) valeur=valeur+(float(consigne-valeur)/50) float (valeur) a=(3-(valeur/50.))*(pi/4) x=100+90*cos(a) y=105-90*sin(a) aiguille=can.create_line(100,105,x,y,width=1,fill="red") root.update() time.sleep(0.002) #Définie l'inertie de l'aiguille (Timer) elif(valeur>consigne): can.delete(aiguille) valeur=valeur+(float(consigne-valeur)/50) float (valeur) a=(3-(valeur/50.))*(pi/4) x=100+90*cos(a) y=105-90*sin(a) aiguille=can.create_line(100,105,x,y,width=1,fill="red") root.update() time.sleep(0.002) #Définie l'inertie de l'aiguille (Timer) else: can.delete(aiguille) float (valeur) a=(3-(valeur/50.))*(pi/4) x=100+90*cos(a) y=105-90*sin(a) aiguille=can1.create_line(100,105,x,y,width=1,fill="red") root.update() time.sleep(0.002) #Définie l'inertie de l'aiguille (Timer) can.update() return ([x,y,consigne]) #------------------------------------------------------------------------- def onAff (can,consigne): if (consigne==100): consigne=consigne-1 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 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) d=0 u=0 # 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") #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") can.update() #------------------------------------------------------------------------- def onLed(can4,consigne): i,j=25,170 can4.create_rectangle(0,0,200,200,fill="white",outline="white") can4.create_rectangle(60,10,140,190,fill="grey") m,j,k,l=25,65,125,175 consigne4=random.randint(0,100) while m<70: can4.create_line(70,m,130,m,width=5,fill="pink") m=m+10 while m<120: can4.create_line(70,m,130,m,width=5,fill="yellow") m=m+10 while m<180: can4.create_line(70,m,130,m,width=5,fill="aquamarine") m=m+10 valeur4=int(consigne4*0.16) while valeur4>=12: can4.create_line(70,j,130,j,width=5,fill="red") valeur4=valeur4-1 j=j-10 while valeur4>=6: can4.create_line(70,k,130,k,width=5,fill="orange") valeur4=valeur4-1 k=k-10 while valeur4>=0: can4.create_line(70,l,130,l,width=5,fill="green") valeur4=valeur4-1 l=l-10 can4.update() #------------------------------------------------------------------------- def onTester(): global select1,select2,select3,select4,select11,select12,select13,select14,module1,module2,module3,module4,valeur,tester valeur=tester consigne1=valeur consigne2=valeur consigne3=valeur consigne4=valeur root.update() if (select11=="Galva "): can1.delete(ALL) try: old1=module1[2] except NameError: old1=0 module1=onGalva(can1,consigne1,old1) elif (select11=="Aff7seg "): can1.delete(ALL) onAff(can1,consigne1) elif (select11=="LEDS "): can1.delete(ALL) onLed(can1,consigne1) else: can1.delete(ALL) can1.create_text(100,100,text="Aucun") if (select13=="Galva "): can2.delete(ALL) try: old2=module2[2] except NameError: old2=0 module2=onGalva(can2,consigne2,old2) elif (select13=="Aff7seg "): can2.delete(ALL) onAff(can2,consigne2) elif (select13=="LEDS "): can2.delete(ALL) onLed(can2,consigne2) else: can2.delete(ALL) can2.create_text(100,100,text="Aucun") if (select12=="Galva "): can3.delete(ALL) try: old3=module3[2] except NameError: old3=0 module3=onGalva(can3,consigne3,old3) elif (select12=="Aff7seg "): can3.delete(ALL) onAff(can3,consigne3) elif (select12=="LEDS "): can3.delete(ALL) onLed(can3,consigne3) else: can3.delete(ALL) can3.create_text(100,100,text="Aucun") if (select14=="Galva "): can4.delete(ALL) try: old4=module4[2] except NameError: old4=0 module4=onGalva(can4,consigne4,old4) elif (select14=="Aff7seg "): can4.delete(ALL) onAff(can4,consigne4) elif (select14=="LEDS "): can4.delete(ALL) onLed(can4,consigne4) else: can4.delete(ALL) can4.create_text(100,100,text="Aucun") root.update() def init(): select11=save11 select12=save12 select13=save13 select14=save14 lab11.configure(text=select11) lab12.configure(text=select12) lab13.configure(text=select13) lab14.configure(text=select14) if (save11=="Galva "): can1.delete(ALL) try: old1=module1[2] except NameError: old1=0 module1=onGalva(can1,0,100) elif (save11=="Aff7seg "): can1.delete(ALL) onAff(can1,consigne1) elif (save11=="LEDS "): can1.delete(ALL) onLed(can1,consigne1) else: can1.delete(ALL) can1.create_text(100,100,text="Aucun") #--------------------------------------------------------------------- if (save13=="Galva "): can2.delete(ALL) try: old2=module2[2] except NameError: old2=0 module2=onGalva(can2,0,100) elif (save13=="Aff7seg "): can2.delete(ALL) onAff(can2,consigne2) elif (save13=="LEDS "): can2.delete(ALL) onLed(can2,consigne2) else: can2.delete(ALL) can2.create_text(100,100,text="Aucun") #------------------------------------------------------------------- if (save12=="Galva "): can3.delete(ALL) try: old3=module3[2] except NameError: old3=0 module3=onGalva(can3,0,100) elif (save12=="Aff7seg "): can3.delete(ALL) onAff(can3,consigne3) elif (save12=="LEDS "): can3.delete(ALL) onLed(can3,consigne3) else: can3.delete(ALL) can3.create_text(100,100,text="Aucun") #--------------------------------------------------------------------- if (save14=="Galva "): can4.delete(ALL) try: old4=module4[2] except NameError: old4=0 module4=onGalva(can4,consigne4,old4) elif (save14=="Aff7seg "): can4.delete(ALL) onAff(can4,consigne4) elif (save14=="LEDS "): can4.delete(ALL) onLed(can4,consigne4) else: can4.delete(ALL) can4.create_text(100,100,text="Aucun") root.update() test() def onSave(): global select1,select2,select3,select4,select11,select12,select13,select14,module1,module2,module3,module4 obFichier = open('config.txt','a') try: obFichier.write (select1) except TypeError: obFichier.write ("aucun ") try: obFichier.write (select2) except TypeError: obFichier.write ("aucun ") try: obFichier.write (select3) except TypeError: obFichier.write ("aucun ") try: obFichier.write (select4) except TypeError: obFichier.write ("aucun ") try: obFichier.write (select11) except TypeError: obFichier.write ("aucun ") try: obFichier.write (select12) except TypeError: obFichier.write ("aucun ") try: obFichier.write (select13) except TypeError: obFichier.write ("aucun ") try: obFichier.write (select14) except TypeError: obFichier.write ("aucun ") obFichier.close() def onSelect1(e): global select1 select1=lst1.get(int(lst1.curselection()[0])) lab1.configure(text=select1) test() def onSelect2(e): global select2 select2=lst2.get(int(lst2.curselection()[0])) lab2.configure(text=select2) test() def onSelect3(e): global select3 select3=lst3.get(int(lst3.curselection()[0])) lab3.configure(text=select3) test() def onSelect4(e): global select4 select4=lst4.get(int(lst4.curselection()[0])) lab4.configure(text=select4) test() def onSelect11(e): global select11 select11=lst11.get(int(lst11.curselection()[0])) lab11.configure(text=select11) test() def onSelect12(e): global select12 select12=lst12.get(int(lst12.curselection()[0])) lab12.configure(text=select12) test() def onSelect13(e): global select13 select13=lst13.get(int(lst13.curselection()[0])) lab13.configure(text=select13) test() def onSelect14(e): global select14 select14=lst14.get(int(lst14.curselection()[0])) lab14.configure(text=select14) test() def test(): global select1,select2,select3,select4,select11,select12,select13,select14,module1,module2,module3,module4 consigne1=random.randint(0,100) consigne2=random.randint(0,100) consigne3=random.randint(0,100) consigne4=random.randint(0,100) if (select11=="Galva "): can1.delete(ALL) try: old1=module1[2] except NameError: old1=0 module1=onGalva(can1,consigne1,old1) elif (select11=="Aff7seg "): can1.delete(ALL) onAff(can1,consigne1) elif (select11=="LEDS "): can1.delete(ALL) onLed(can1,consigne1) else: can1.delete(ALL) can1.create_text(100,100,text="Aucun") if (select13=="Galva "): can2.delete(ALL) try: old2=module2[2] except NameError: old2=0 module2=onGalva(can2,consigne2,old2) elif (select13=="Aff7seg "): can2.delete(ALL) onAff(can2,consigne2) elif (select13=="LEDS "): can2.delete(ALL) onLed(can2,consigne2) else: can2.delete(ALL) can2.create_text(100,100,text="Aucun") if (select12=="Galva "): can3.delete(ALL) try: old3=module3[2] except NameError: old3=0 module3=onGalva(can3,consigne3,old3) elif (select12=="Aff7seg "): can3.delete(ALL) onAff(can3,consigne3) elif (select12=="LEDS "): can3.delete(ALL) onLed(can3,consigne3) else: can3.delete(ALL) can3.create_text(100,100,text="Aucun") if (select14=="Galva "): can4.delete(ALL) try: old4=module4[2] except NameError: old4=0 module4=onGalva(can4,consigne4,old4) elif (select14=="Aff7seg "): can4.delete(ALL) onAff(can4,consigne4) elif (select14=="LEDS "): can4.delete(ALL) onLed(can4,consigne4) else: can4.delete(ALL) can4.create_text(100,100,text="Aucun") root.update() def quitter(): obFichier = open('config.txt','a') try: obFichier.write (select1) except TypeError: obFichier.write ("aucun ") try: obFichier.write (select2) except TypeError: obFichier.write ("aucun ") try: obFichier.write (select3) except TypeError: obFichier.write ("aucun ") try: obFichier.write (select4) except TypeError: obFichier.write ("aucun ") try: obFichier.write (select11) except TypeError: obFichier.write ("aucun ") try: obFichier.write (select12) except TypeError: obFichier.write ("aucun ") try: obFichier.write (select13) except TypeError: obFichier.write ("aucun ") try: obFichier.write (select14) except TypeError: obFichier.write ("aucun ") obFichier.close() root.quit() root=Tk() tester=StringVar() can1=Canvas(width=200,height=200,bg="white") can2=Canvas(width=200,height=200,bg="white") can3=Canvas(width=200,height=200,bg="white") can4=Canvas(width=200,height=200,bg="white") bou1=Button(root,text="Sauver et quitter",command=quitter) bou2=Button(root,text="Rafraichir",command=test) bou3=Button(root,text="Enregistrer",command=onSave) bou4=Button(root,text="Annuler",command=root.quit) bou5=Button(root,text="Tester",command=onTester) lbl1=Label(root,text="Valeur test :") ent1=Entry(root,textvariable=tester) lst1=Listbox(root) lab1=Label(root,text="_") lst1.grid(row=0,column=1) lab1.grid(row=1,column=1) #------------------------------------------------------------------------- for grandeur in ['% CPU1 ' , '% CPU2 ', '% CPU3 ', '% CPU4 ', '% RAM ' , "% GPU " , "T cpu " , "T gpu " ]: lst1.insert(END,grandeur) lst1.bind('<Double-1>',onSelect1) lst2=Listbox(root) lab2=Label(root,text="_") lst2.grid(row=0,column=4) lab2.grid(row=1,column=4) for grandeur in ['% CPU1 ' , '% CPU2 ', '% CPU3 ', '% CPU4 ', '% RAM ' , "% GPU " , "T cpu " , "T gpu " ]: lst2.insert(END,grandeur) lst2.bind('<Double-1>',onSelect2) lst3=Listbox(root) lab3=Label(root,text="_") lst3.grid(row=2,column=1) lab3.grid(row=3,column=1) for grandeur in ['% CPU1 ' , '% CPU2 ', '% CPU3 ', '% CPU4 ', '% RAM ' , "% GPU " , "T cpu " , "T gpu " ]: lst3.insert(END,grandeur) lst3.bind('<Double-1>',onSelect3) lst4=Listbox(root) lab4=Label(root,text="_") lst4.grid(row=2,column=4) lab4.grid(row=3,column=4) for grandeur in ['% CPU1 ' , '% CPU2 ', '% CPU3 ', '% CPU4 ', '% RAM ' , "% GPU " , "T cpu " , "T gpu " ]: lst4.insert(END,grandeur) lst4.bind('<Double-1>',onSelect4) #------------------------------------------------------------------------- lst11=Listbox(root) lab11=Label(root,text="_") lst11.grid(row=0,column=2) lab11.grid(row=1,column=2) for grandeur in ["Galva ","Aff7seg ","LEDS "]: lst11.insert(END,grandeur) lst11.bind('<Double-1>',onSelect11) lst12=Listbox(root) lab12=Label(root,text="_") lst12.grid(row=0,column=5) lab12.grid(row=1,column=5) for grandeur in ["Galva ","Aff7seg ","LEDS "]: lst12.insert(END,grandeur) lst12.bind('<Double-1>',onSelect12) lst13=Listbox(root) lab13=Label(root,text="_") lst13.grid(row=2,column=2) lab13.grid(row=3,column=2) for grandeur in ["Galva ","Aff7seg ","LEDS "]: lst13.insert(END,grandeur) lst13.bind('<Double-1>',onSelect13) lst14=Listbox(root) lab14=Label(root,text="_") lst14.grid(row=2,column=5) lab14.grid(row=3,column=5) for grandeur in ["Galva ","Aff7seg ","LEDS "]: lst14.insert(END,grandeur) lst14.bind('<Double-1>',onSelect14) can1.grid(row=0,column=0) can2.grid(row=2,column=0) can3.grid(row=0,column=3) can4.grid(row=2,column=3) bou1.grid(row=10,column=5) bou2.grid(row=10,column=0) bou3.grid(row=10,column=1) bou4.grid(row=10,column=4) lbl1.grid(row=4,column=0) ent1.grid(row=4,column=1) bou5.grid(row=4,column=2) init() #--------------------------------------------------------------------------------------------------------------------------- root.mainloop() # démarrage du réceptionnaire d'événements
|
|
Cette discussion est classée dans : width, line, can, create, fill
Répondre à ce message
Sujets en rapport avec ce message
[Python][Classe] intégration fonction "def" dans une classe [ par Acolyte ]
Bonsoir à tous, J'ai un petit problème je veux créer un module digit qui permet d'afficher des chiffres digitaux (virtuel) comme sur les anciens radio
encodage [ par rezuz ]
voila ils se trouve que j'ai un petit problemme dans mon code. j'ais une chaine de caractère avec des carctere unicode donc que je voudrait encodé en
Demande d'aide à l'optimisation [ par elnabo ]
Bonjour, ayant réaliser un petit code permettant de déplacer un petit rond d'avant en arrière et lui permettant des rotations, à l'aide du clavier en
Débuter avec PythonPortable [ par Tarc91 ]
Bonjour, Je développe en VBA sous Excel (niveau moyen) et je souhaiterais me lancer dans l'apprentissage de Python. J'utilise PortablePython pour Wind
URGENT!! Probleme tetris python [ par basic50 ]
Bonjour à tous, voila j'ai un soucis sur un petit programme de tetris en python. J'ai réussit à faire le programme, tt du moins la base(les tetris se
Il me manque une librairie [ par cipher16 ]
Bonjour ... je viens de commencer à coder en python ... et il semblerai qu'il me manque une librairie ayant un rapport avec internet ... J'ai cherché
probleme d'execution [ par albatof ]
Bonjour,Avant d'apprendre a se servir d 'un module graphique, j'ai fait la comparaison entre gtk, tk et wx.wx: a l'air d'être trop compliqué.tk: sa fe
MemoryLoadLibrary [ par laurent 50 ]
Bonjour à tous, Je travail avec la version 2.5.2 de python et avec la version 0.6.9 du module py2exe. La compilation de mon application se déroule san
Livres en rapport
|
Derniers Blogs
ENUMERABLECOLLECTIONENUMERABLECOLLECTION par Matthieu MEZIL
Prenons le scénario suivant. On utilise MVVM. On a les deux classes suivantes dans le model : public class Child { } public class Parent { private ObservableCollection < Child > _children; public ObservableCollection < Child > Children { get {...
Cliquez pour lire la suite de l'article par Matthieu MEZIL [HS] CHROME 6 + MOI = COUP DE GUEULE ![HS] CHROME 6 + MOI = COUP DE GUEULE ! par JeremyJeanson
Attention, le poste qui suit n'est pas la complainte d'une personne : Qui n'aime pas Chrome. D'un anti Google. D'un développeur qui a un poil énorme dans la main. Ceux qui me fréquentent savent que je change de navigateur favori tous les 2 ou 3 mois afin ...
Cliquez pour lire la suite de l'article par JeremyJeanson [WP7] UTILISER UN WRAPPANEL DANS UNE APPLICATION WINDOWS PHONE 7[WP7] UTILISER UN WRAPPANEL DANS UNE APPLICATION WINDOWS PHONE 7 par Audrey
Lors de la réalisation de ma 2ème application Windows Phone 7, j'ai souhaité utiliser un WrapPanel pour afficher plusieurs photos. Mais le contrôle WrapPanel ne fait pas parti de la liste des contrôles inclus dans le SDK de la version Beta des outils pour...
Cliquez pour lire la suite de l'article par Audrey [WP7] BESOIN D'AVOIR DES DONNéES EN CACHE[WP7] BESOIN D'AVOIR DES DONNéES EN CACHE par Nicolas
Les développeurs ASP.NET ont l'habitude de mettre des données en cache pour éviter de requêter a chaque fois la base de données. Et il est toujours utilie de penser que vos utilisateurs mobiles n'ont pas troujours une super connexion 3G/WIFI et un for...
Cliquez pour lire la suite de l'article par Nicolas [TFS] COMMENT FORCER LA SAISIE D'UN AREA OU ITERATION[TFS] COMMENT FORCER LA SAISIE D'UN AREA OU ITERATION par cyril
Lorsque l'on créé un Work Item dans TFS, il est possible de le classer dans un "area" et dans une "iteration". Dans la plupart des types de projet, un "area" correspond à une catégorie, une "iteration" à un numéro de version. Il est possible de cré...
Cliquez pour lire la suite de l'article par cyril
Forum
RE : PYTHON 3.0RE : PYTHON 3.0 par aera group
Cliquez pour lire la suite par aera group RE : PYTHON 3.0RE : PYTHON 3.0 par xeolin
Cliquez pour lire la suite par xeolin RE : PYTHON 3.0RE : PYTHON 3.0 par aera group
Cliquez pour lire la suite par aera group
Logiciels
uTorrent (2.0.4)UTORRENT (2.0.4)C'est un client BitTorrent très puissant et très performant. Comme son nom l'indique, uTorrent (m... Cliquez pour télécharger uTorrent Bureau de Gestion - ERP Devis Facturation (2.02)BUREAU DE GESTION - ERP DEVIS FACTURATION (2.02)- Version gratuite du 10/06/2010
Le Bureau de Gestion est un logiciel dédié à la gestion de l'en... Cliquez pour télécharger Bureau de Gestion - ERP Devis Facturation 4Videosoft Transfert iPod Mac (3.2.08)4VIDEOSOFT TRANSFERT IPOD MAC (3.2.08)4Videosoft Transfert iPod-Mac caractérise principalement à transférer les fichiers iPod vers Mac.... Cliquez pour télécharger 4Videosoft Transfert iPod Mac 4Videosoft HD Convertisseur (3.3.08)4VIDEOSOFT HD CONVERTISSEUR (3.3.08)Etant le meilleur HD Vidéo Convertisseur, 4Videosoft HD Convertisseur, vous pouvez regarder la vi... Cliquez pour télécharger 4Videosoft HD Convertisseur 4Videosoft Transfert iPad Mac (3.2.08)4VIDEOSOFT TRANSFERT IPAD MAC (3.2.08)4Videosoft Transfert iPad-Mac est un logiciel managérial iPad professionnel qui a des fonctions i... Cliquez pour télécharger 4Videosoft Transfert iPad Mac
|