1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
import matplotlib.pyplot as plt
import math
import numpy as np
import tkinter as tk
from tkinter import ttk
fenetre = tk.Tk()
fenetre.geometry("600x150")
frame_titre = tk.Frame ()
frame_zone1 = tk.Frame ()
frame_zone2 = tk.Frame ()
frame_zone3 = tk.Frame ()
zoneTexte = tk.Label(frame_titre,text="Calcul du pH d'une solution",font=("Arial",20))
zoneTexte.pack(side=tk.TOP) # à chaque élément graphique appelé, il faut mettre un pack
frame_titre.pack()
esp=["Choisir une espèce","CH3COOH", "HF"]
choix_esp = ttk.Combobox(fenetre,values=esp)
choix_esp.current(0)
choix_esp.pack()
question = tk.Label(frame_zone1,text="La solution a une concentration de 10^ :",font=("Arial",10))
question.pack(side=tk.LEFT)
frame_zone1.pack()
saisie = tk.Entry(frame_zone1,width=5)
saisie.pack(side=tk.LEFT)
frame_zone1.pack()
reponse= tk.Label(frame_zone2,text="",font=("Arial",10))
reponse.pack(side=tk.TOP)
frame_zone1.pack()
bouton = tk.Button (frame_zone2,text ="valider")
bouton.pack(side=tk.BOTTOM)
frame_zone2.pack(side=tk.BOTTOM)
def action():
x=0
select = choix_esp.get()
if select=="CH3COOH":
x=4.75
x=float(x)
elif select=="HF":
x=3.17
x=float(x)
def affichage():
global zoneTexte
puissance = saisie.get()
question.config(text="")
le_pH=[]
aH1=[]
aHY1=[]
a1=[]
aY1=[]
oH=[]
oHY=[]
h=[]
hY=[]
pkA=[]
puissance=float(puissance)
c0=10**(puissance)
logCalc=math.log(c0,10)
pkA.append(x)
pkAY=[0,-14]
point=float(x)
pointY=logCalc- 0.3
### préparation des listes pH oH H
pH=0
while pH<14:
oH.append(round(pH,4))
oHY.append(round(-14+pH,4))
pH=pH+0.01
pH=0
while pH<14:
h.append(round(pH,4))
hY.append(round(-pH,4))
pH=pH+0.01
pH=0
while pH<14:
le_pH.append(round(pH,4))
pH=pH+0.01
##### préparation des listes aH a-
pH=0
pKA=x
limitebas=pKA-1.5
limitebas=float(limitebas)
limitehaut=pKA+1.5
limitehaut=float(limitehaut)
i=0
while pH<14:
aH1.append(pH)
aHY1.append(round(logCalc-math.log(1+((10**-pKA)/10**-pH),10),4))
a1.append(pH)
aY1.append(round(logCalc-math.log(1+((10**-pH)/10**-pKA),10),4))
pH=pH+0.01
i=i+1
# Afficher la courbe
plt.plot(aH1,aHY1,'-r',label="AH")
plt.plot(a1,aY1,'-b',label="A-")
plt.plot(oH,oHY,':g',label="OH")
plt.plot(h,hY,':y',label="H+")
plt.plot(pkA,pkAY,'--',label="pKA")
plt.plot(point,pointY,'*k')
plt.ylim(-9,0)
plt.legend()
##### pour trouver le pH
sol=[]
i=0
pH=0
while pH<14:
if (round(logCalc-math.log(1+((10**-pH)/10**-pKA),10),4)) > (round(-pH,4))-0.01 and (round(logCalc-math.log(1+((10**-pH)/10**-pKA),10),4)) < (round(-pH,4))+0.01:
sol.append(pH)
pH=round(pH+0.01,4)
if sol[0] != "":
resultat=round(np.mean(sol),2)
reponse.config(text="Le pH de la solution est de "+str(resultat))
else :
reponse.config(text="N'a pas trouvé de solution")
question.config(text="Pour une concentration de : 10^")
choix_esp.bind("<<ComboboxSelected>>", action)
bouton.config(command=affichage)
fenetre.mainloop() |
Partager