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
| #!/usr/bin/env python
# -*- coding: cp1252 -*-
#
#
# Prototype de l'interface de notre programme
from math import *
try:
from tkinter import *
except:
from Tkinter import *
def pol():
ca = e0.get()
pka = e1.get()
equation_index = myvar.get()
if equation_index == 0:
fenwarn = Toplevel(fen1)
fenwarn.title('Erreur')
Label(fenwarn, text='Vous devez choisir un type').pack(padx=5, pady=5)
Button(fenwarn, text='Ok', command = fenwarn.destroy).pack(padx=5, pady=5)
return
elif equation_index == 1:
rep=0.5*(float(pka))-0.5*log10(float(ca))
elif equation_index == 2:
rep=7+0.5*(float(pka))+0.5*log10(float(ca))
elif equation_index == 3:
rep=-log10(float(ca))
elif equation_index == 4:
rep=14+log10(float(ca))
print("Voici le résultat, pour une concentration de", ca, "mol/l et un pka de", pka, ", le ph est de", rep)
Result['text'] = "Résultat : " + str(rep)
def fen2show():
fen2 = Toplevel(fen1)
fen2.title('Courbe de titrage')
Label(fen2, text='Courbe de titrage').pack(padx=5, pady=5)
Button(fen2, text='Fermer', command = fen2.destroy).pack(padx=5, pady=5)
fen1 = Tk()
fen1.title("Calcul de pH")
myvar= IntVar()
Label(fen1, text="Quel est le type de l'espèce considérée ?").grid(row=0, column=1, columnspan=2, padx=5, pady=5)
Radiobutton(fen1,text="Acide faible", variable=myvar, value=1, indicatoron=0).grid(row=1, column=1, padx=5, pady=5, ipady=5, sticky=W+E)
Radiobutton(fen1,text="Base faible ", variable=myvar, value=2, indicatoron=0).grid(row=2, column=1, padx=5, pady=5, ipady=5, sticky=W+E)
Radiobutton(fen1,text="Acide fort", variable=myvar, value=3, indicatoron=0).grid(row=1, column=2, padx=5, pady=5, ipady=5, sticky=W+E)
Radiobutton(fen1,text="Base forte", variable=myvar, value=4, indicatoron=0).grid(row=2, column=2, padx=5, pady=5, ipady=5, sticky=W+E)
Label(fen1, text="Concentration de l'espèce en question (en mol/l) :").grid(row=0, column=3, padx=5, pady=5)
e0=Entry(fen1, width=20, justify=CENTER)
e0.grid(row=1, column=3)
Label(fen1, text="pka ?").grid(row=2, column=3)
e1=Entry(fen1, width=20, justify=CENTER)
e1.grid(row=3, column=3)
Button(fen1, text="Courbe de titrage", command=fen2show).grid(row=4, column=1, columnspan=2, pady=15)
Button(fen1, text="Calcul du pH", command=pol).grid(row=4, column=3, pady=15)
Frame(fen1, height=2, bd=1, relief=SUNKEN).grid(row=5, column=1, columnspan=3, padx=5, pady=5, sticky=W+E)
Result = Label(fen1, text="Résultat :", justify=CENTER)
Result.grid(row=6, column=1, columnspan=3, padx=5, pady=5, sticky=W+E)
fen1.mainloop() |