|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
TRACER UNE FONCTION
Information sur la source
Description
Juste une appli me permettant de tracer des fonction:
Exemple: cos(x)
Nota Bene:Entrer (x)**2 au lieu de x**2
Source
- # -*- coding: iso8859-15 -*-
-
- from Tkinter import*
- from math import*
- import tkMessageBox
-
-
- ref=[]
- dic={}
- class Application(Frame):
- """Mise en place de l'interface"""
- def __init__(self):
- Frame.__init__(self)
- self.master.title("::.Ma fonction.::-By Kouakou021988")
- 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(side=TOP)
- self.coul=['red','blue','yellow','green']
- self.coord=[]
- self.courb=['none']
- self.build()
-
- def build(self):
- """mise en place des bouton,..."""
- Label(self,text="f(x): ",font='arial 10 italic',background='grey40',fg='white').pack(side=LEFT)
- self.ent_fct=Entry(self,width=25,font='arial 10 bold',relief=FLAT,fg='black')
- self.ent_fct.pack(side=LEFT,fill=BOTH,expand=1)
- Button(self,text="Tracer",font='arial 8 bold',background='grey40',
- foreground='white',command=self.traceur).pack(side=RIGHT)
- self.can=Canvas(self.master,bg='black',height=400,width=600)
- self.can.pack(side=LEFT,fill=BOTH,expand=1)
- pas=25
- self.can.create_line(10,200,600,200,arrow=LAST,fill='white') #axe x
- for x in range(1,11):
- stx=300+x*pas
- self.can.create_line(stx,0,stx,400,fill='grey40') #196/204
- self.can.create_text(stx,210,text=str(x),fill='white',font='arial 6')
- for x in range(1,11):
- stx=300-x*pas
- self.can.create_line(stx,0,stx,400,fill='grey40')
- self.can.create_text(stx,210,text='-'+str(x),fill='white',font='arial 6')
- self.can.create_line(300,395,300,5,arrow=LAST,fill='white') #axe y
- for y in range(1,8):
- sty=200+y*pas
- self.can.create_line(0,sty,600,sty,fill='grey40') #296/304
- self.can.create_text(310,sty,text='-'+str(y),fill='white',font='arial 6')
- for y in range(1,8):
- sty=200-y*pas
- self.can.create_line(0,sty,600,sty,fill='grey40')
- self.can.create_text(310,sty,text=str(y),fill='white',font='arial 6')
- self.can.create_text(305,210,text=str(0),fill='white',font='arial 6')
- fram=Frame(self.master)
- fram.pack(side=RIGHT)
- self.lstbox=Listbox(fram,height=5,font='arial 8 bold',fg='black')
- self.lstbox.pack(side=TOP)
- self.lstbox.insert(END,'none')
- Button(fram,text="Reset",font='arial 8',command=self.reset).pack(side=LEFT)
- self.re=Button(fram,text="Effacer Tracé",font='arial 8',command=self.efface)
- self.re.pack(side=LEFT)
- self.re.config(state=DISABLED)
- self.lstbox.bind("<Button-1>",self.option)
-
- def option(self,event=None):
- self.master.update()
- y=event.y
- y=self.lstbox.nearest(y)
- y=self.lstbox.get(y)
- if y!='none':
- if ref:
- for i in ref:
- for x in i: self.can.itemconfig(x, width =1)
- self.re.config(state=NORMAL)
- self.y=y #nom de la fct dans le listbox
- self.coord=dic[self.y]
- ref.append(self.coord)
- for i in self.coord:
- self.can.itemconfig(i, width =3)
- self.can.lift(i)
- if y=='none':
- if self.coord:
- for i in self.coord:
- self.can.itemconfig(i, width =1)
- self.re.config(state=DISABLED)
-
- def efface(self):
- try:
- for i in self.coord:
- self.can.delete(i)
- s=self.courb.index(self.y)
- self.lstbox.delete(s)
- self.courb.remove(self.y)
- self.initialise(self.y)
- fin=dic.pop(self.y)
- self.re.config(state=DISABLED)
- except: pass
-
- def initialise(self,f):
- c=f.split('-->')[1]
- c=c[1:len(c)-1]
- self.coul.append(c)
-
- def traceur(self):
- fct=self.ent_fct.get()
- if fct:
- try: c=self.coul.pop()
- except: tkMessageBox.showerror("Ma fonction","Limite de fonction atteinte")
- else:
- self.ph="f(x)="+fct+"-->("+c+")"
- self.courbe(fct,c)
- self.lstbox.insert(END,self.ph)
- self.courb.append(self.ph)
- else: pass
-
- def reset(self):
- try:
- l=dic.keys()
- for i in l:
- a=dic.pop(i)
- for x in a: self.can.delete(x)
- self.lstbox.delete(1,END)
- except: pass
- self.coul=['red','blue','yellow','green']
-
- def courbe(self,fonction="(x)**2.",color="red"):
- """Courbe de la fonction:'(x)**2.' par defaut"""
- self.func=fonction
- curve=[]
- x=0
- while x<12:
- try:
- if "exp" in self.func:
- self.func=fonction.replace('exp','zzz')
- self.func=self.func.replace('x',str(x))
- self.func=self.func.replace('zzz','exp')
- y=eval(self.func)
- else: y=eval(self.func.replace('x',str(x)))
- except: pass
- else: curve.append((x*25+300,(-y)*25+200))
- x+=0.01
- try: a=self.can.create_line(curve,fill=color,smooth=1)
- except: a=""
- x=0
- curve=[]
- while x>-12.0:
- try:
- if "exp" in self.func:
- self.func=fonction.replace('exp','zzz')
- self.func=self.func.replace('x',str(x))
- self.func=self.func.replace('zzz','exp')
- y=eval(self.func)
- else: y=eval(self.func.replace('x',str(x)))
- except: pass
- else: curve.append((x*25+300,(-y)*25+200))
- x-=0.01
- try: b=self.can.create_line(curve,fill=color,smooth=1)
- except: b=""
- dic[self.ph]=(a,b)
-
- def test(self,v):
- pass
-
- def quitter(self):
- self.can.delete(ALL)
- self.master.destroy()
-
-
-
- ###--------------------------------------------------------------##############
- if __name__=='__main__':
- app=Application()
- app.mainloop()
# -*- coding: iso8859-15 -*-
from Tkinter import*
from math import*
import tkMessageBox
ref=[]
dic={}
class Application(Frame):
"""Mise en place de l'interface"""
def __init__(self):
Frame.__init__(self)
self.master.title("::.Ma fonction.::-By Kouakou021988")
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(side=TOP)
self.coul=['red','blue','yellow','green']
self.coord=[]
self.courb=['none']
self.build()
def build(self):
"""mise en place des bouton,..."""
Label(self,text="f(x): ",font='arial 10 italic',background='grey40',fg='white').pack(side=LEFT)
self.ent_fct=Entry(self,width=25,font='arial 10 bold',relief=FLAT,fg='black')
self.ent_fct.pack(side=LEFT,fill=BOTH,expand=1)
Button(self,text="Tracer",font='arial 8 bold',background='grey40',
foreground='white',command=self.traceur).pack(side=RIGHT)
self.can=Canvas(self.master,bg='black',height=400,width=600)
self.can.pack(side=LEFT,fill=BOTH,expand=1)
pas=25
self.can.create_line(10,200,600,200,arrow=LAST,fill='white') #axe x
for x in range(1,11):
stx=300+x*pas
self.can.create_line(stx,0,stx,400,fill='grey40') #196/204
self.can.create_text(stx,210,text=str(x),fill='white',font='arial 6')
for x in range(1,11):
stx=300-x*pas
self.can.create_line(stx,0,stx,400,fill='grey40')
self.can.create_text(stx,210,text='-'+str(x),fill='white',font='arial 6')
self.can.create_line(300,395,300,5,arrow=LAST,fill='white') #axe y
for y in range(1,8):
sty=200+y*pas
self.can.create_line(0,sty,600,sty,fill='grey40') #296/304
self.can.create_text(310,sty,text='-'+str(y),fill='white',font='arial 6')
for y in range(1,8):
sty=200-y*pas
self.can.create_line(0,sty,600,sty,fill='grey40')
self.can.create_text(310,sty,text=str(y),fill='white',font='arial 6')
self.can.create_text(305,210,text=str(0),fill='white',font='arial 6')
fram=Frame(self.master)
fram.pack(side=RIGHT)
self.lstbox=Listbox(fram,height=5,font='arial 8 bold',fg='black')
self.lstbox.pack(side=TOP)
self.lstbox.insert(END,'none')
Button(fram,text="Reset",font='arial 8',command=self.reset).pack(side=LEFT)
self.re=Button(fram,text="Effacer Tracé",font='arial 8',command=self.efface)
self.re.pack(side=LEFT)
self.re.config(state=DISABLED)
self.lstbox.bind("<Button-1>",self.option)
def option(self,event=None):
self.master.update()
y=event.y
y=self.lstbox.nearest(y)
y=self.lstbox.get(y)
if y!='none':
if ref:
for i in ref:
for x in i: self.can.itemconfig(x, width =1)
self.re.config(state=NORMAL)
self.y=y #nom de la fct dans le listbox
self.coord=dic[self.y]
ref.append(self.coord)
for i in self.coord:
self.can.itemconfig(i, width =3)
self.can.lift(i)
if y=='none':
if self.coord:
for i in self.coord:
self.can.itemconfig(i, width =1)
self.re.config(state=DISABLED)
def efface(self):
try:
for i in self.coord:
self.can.delete(i)
s=self.courb.index(self.y)
self.lstbox.delete(s)
self.courb.remove(self.y)
self.initialise(self.y)
fin=dic.pop(self.y)
self.re.config(state=DISABLED)
except: pass
def initialise(self,f):
c=f.split('-->')[1]
c=c[1:len(c)-1]
self.coul.append(c)
def traceur(self):
fct=self.ent_fct.get()
if fct:
try: c=self.coul.pop()
except: tkMessageBox.showerror("Ma fonction","Limite de fonction atteinte")
else:
self.ph="f(x)="+fct+"-->("+c+")"
self.courbe(fct,c)
self.lstbox.insert(END,self.ph)
self.courb.append(self.ph)
else: pass
def reset(self):
try:
l=dic.keys()
for i in l:
a=dic.pop(i)
for x in a: self.can.delete(x)
self.lstbox.delete(1,END)
except: pass
self.coul=['red','blue','yellow','green']
def courbe(self,fonction="(x)**2.",color="red"):
"""Courbe de la fonction:'(x)**2.' par defaut"""
self.func=fonction
curve=[]
x=0
while x<12:
try:
if "exp" in self.func:
self.func=fonction.replace('exp','zzz')
self.func=self.func.replace('x',str(x))
self.func=self.func.replace('zzz','exp')
y=eval(self.func)
else: y=eval(self.func.replace('x',str(x)))
except: pass
else: curve.append((x*25+300,(-y)*25+200))
x+=0.01
try: a=self.can.create_line(curve,fill=color,smooth=1)
except: a=""
x=0
curve=[]
while x>-12.0:
try:
if "exp" in self.func:
self.func=fonction.replace('exp','zzz')
self.func=self.func.replace('x',str(x))
self.func=self.func.replace('zzz','exp')
y=eval(self.func)
else: y=eval(self.func.replace('x',str(x)))
except: pass
else: curve.append((x*25+300,(-y)*25+200))
x-=0.01
try: b=self.can.create_line(curve,fill=color,smooth=1)
except: b=""
dic[self.ph]=(a,b)
def test(self,v):
pass
def quitter(self):
self.can.delete(ALL)
self.master.destroy()
###--------------------------------------------------------------##############
if __name__=='__main__':
app=Application()
app.mainloop()
Conclusion
Sources du même auteur
Sources de la même categorie
Sources en rapport avec celle ci
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
wxWindow::RegisterHotKey [ par DoudouBidou ]
Bonjour à tous(au passage Merci pour ce site, depuis le temps que je l'attends...)J'utilise wxPython pour réaliser mon interface graphique mais je n'a
probleme avec os.path.getctime() [ par Bl0tCh ]
Voilà, Donc cette fonction est censée me donner la date de creation du fichier (en secondes) mais le probleme c ke elle me donne la premiere date de c
liste des process en cours [ par rodrigos ]
Bonjour, Je suis sous windows et je cherche à obtenir la liste des process en cours sur le pc. La seule foncyion que j'ai rouvé est la fonc
Zope: Contenu d'une liste en fonction d'une autre [ par keumlebarbare ]
AU SECOURS!!!! Je suis tout ce qu'il y a de plus débutant en Zope, et je crois que si je continue à galérer comme ca, je me (re)met a
Ou trouver la liste des fonction disponible... [ par CotCouture ]
Bonjour j'aimerais savoir ou je peux trouver la liste des fonction disponible dans les logiciel office? Cot Couture
fonction inconnue [ par xeolin ]
je voulai creer cette discussion pour que l'on fasse un jeu : le but est : mettre des fonction que personne utilise ! ca parais bidon mais ca peut
existe -t-il un équivalent de la fonction "call" sous Python? [ par Veust ]
Bonjour, je suis en train d'ecrire un code sous python qui d'une part doit rentrer des donner dans une liste(jusque là facile) et d'autre part créer u
Appel d'une fonction [ par Thomeux ]
Bonjour,Je débute en python.J'essais de structurer mon Programme de la manière suivante :Un fichier bibliothèque fonction, :Un Fichi
utiliser correctement les fonction, débutant niveaux 0+ dx [ par gwenc_hlan ]
voilà, en gros, ça fait une semaine que je fait du python et en totu un peu plus de dix jours que je programme. engros : je débute.bon, voilà, je suis
définir une fonction dans une fonction ? [ par gwenc_hlan ]
bonjour, voilà, je cherche à faire un petit programme à interface graphiques. cependant, j'aimerais savoir s'il est possible de définir une fonction
|
Téléchargements
Logiciels à télécharger sur le même thème :
Comparez les prix Nouvelle version
|