from tkinter import * from sympy import * ln = log x, y = symbols('x y') # 2D from sympy.plotting import plot, plot_implicit, plot_parametric """ plot(x**3-3*x+1,(x,-2,3)) plot_implicit((x-3)**2+(y+2)**2<4,(x,0,6),(y,-5,1)) plot_implicit(3*x*y-y**2-1) plot_parametric(cos(3*x),sin(2*x),(x,-6,6))""" # 3D from sympy.plotting import plot3d, plot3d_parametric_line, plot3d_parametric_surface """ plot3d(x**2-y**2,(x,-5,5),(y,-5,5)) plot3d_parametric_line(cos(x),sin(x),x,(x,-15,15)) plot3d_parametric_surface(cos(2*x+y),sin(y-x),x-y,(x,-5,5),(y,-5,5))""" def dessin(i): message.set("Terminé ! ") if i == 0: plot(sympify(express.get()), (x,-2,3)) elif i == 1: plot_implicit(sympify(express.get())) elif i == 2: plot_parametric(eval(express.get()), (x,-6,6)) elif i == 3: plot3d(sympify(express.get()), (x,-5,5), (y,-5,5)) elif i == 4: f = eval(express.get()) plot3d_parametric_line(f[0], f[1], f[2], (x,-15,15)) elif i == 5: f = eval(express.get()) plot3d_parametric_surface(f[0], f[1], f[2], (x,-5,5), (y,-5,5)) def calcul(i): if i == 0: c = expand(sympify(express.get())) elif i == 1: c = factor(sympify(express.get())) elif i == 2: c = integrate(sympify(express.get()), x) elif i == 3: c = diff(sympify(express.get()), x) elif i == 4: c = series(sympify(express.get()), x, 0, 6) elif i == 5: c = limit(sympify(express.get()), x, 0) elif i == 6: c = limit(sympify(express.get()), x, oo) elif i == 7: c = solve(sympify(express.get()), x) if len(str(c)) > 20: for i in range(len(c)): c[i] = c[i].evalf(3) return str(c) def init(): message.set("") def jeu(): init() cd = choix() if cd == 1: mes=mot.get() + " : " + calcul(selection.get()) message.set(mes) elif cd == 2: message.set("Patience ... ") dessin(selection.get()) fen = Tk() fen.title("Calculatrice SB") mot = StringVar() motsaisi = StringVar() trad = StringVar() res = StringVar() choix1 = IntVar() choix2 = IntVar() cpt = IntVar() nbtest = IntVar() lab1 = Label(fen, text="Maths en Python", font=('Times', '24', 'bold italic')) lab1.grid(row=0, column=0, columnspan=3) lab2 = Label(fen, text="Choisir un calcul ou un dessin", font=('Times', '18', 'bold italic'), pady=20) lab2.grid(row=1, column=0, columnspan=3) vcb1 = IntVar() vcb2 = IntVar() def choix(): x, y=vcb1.get(), vcb2.get() if x * y != 0: lab4.configure(fg="red") message.set("Attention ! Choisir calcul ou dessin puis valider") else: lab4.configure(fg="black") return 1 * vcb1.get() + 2 * vcb2.get() cb1 = Checkbutton(fen, text='Calcul', font=('Times', '16', 'bold italic'), variable=vcb1, borderwidth=6, width=25, padx=20, pady=25, relief='solid') cb1.grid(row=2, column=0) cb2=Checkbutton(fen, text='Dessin', font=('Times', '16', 'bold italic'), variable=vcb2, borderwidth=6, width=25, padx=20, pady=25, relief='solid') cb2.grid(row=2, column=2) lab3=Label(fen, text="Entrer dans le cadre l'expression étudiée : ", font=('Times', '14', 'bold italic'), pady=30) lab3.grid(row=3, column=0, columnspan=2) express = StringVar() saisi2 = Entry(fen, width=30, font=('Times', '14', 'normal'), textvariable=express) saisi2.grid(row=3, column=2) selection = IntVar() def clic(evt): i = lbox.curselection() ## Récupération de l'index de l'élément sélectionné #print (lbox.get(i)) ## On retourne l'élément (un string) sélectionné selection.set(int(i[0])) lboxvar = StringVar() lboxvar.set(('Courbe y=f(x)', 'Courbe implicite f(x,y)=0', 'Courbe paramétrée f(x),g(x)', 'Surface espace z=f(x,y)', 'Courbe paramétrée espace f(x),g(x),x', 'Surface paramétrée espace f(x,y),g(x,y),h(x,y)')) lbox = Listbox(fen, bg='#888800', bd=6, font=('Times', '12', 'bold italic'), width=40, listvariable=lboxvar) lbox.grid(row=4, column=2) lbox.bind('', clic) mot = StringVar() def clic2(evt): i = lbox2.curselection() ## Récupération de l'index de l'élément sélectionné mot.set(lbox2.get(i)) ## On retourne l'élément (un string) sélectionné selection.set(int(i[0])) lboxvar2 = StringVar() lboxvar2.set(('Développement', 'Factorisation', 'Primitive', 'Dérivée', 'Développement en série', 'Limite en 0', 'Limite en +oo', 'Résolution f(x)=0, f polynôme')) lbox2 = Listbox(fen, bg='#008888', bd=6, font=('Times', '12', 'bold italic'), width=35, listvariable=lboxvar2) lbox2.grid(row=4, column=0) lbox2.bind('', clic2) b2=Button(fen, text="Valider", bg="#008800", font=('Times', '12', 'bold'), pady=10, relief='solid', command=jeu) b2.grid(row=5, column=1, ipadx=20) message = StringVar() lab4=Label(fen, textvariable=message, font=('Times', '14', 'bold'), pady=20) lab4.grid(row=6, column=0, columnspan=3) b1=Button(fen, text="Quitter", pady=10, command=fen.destroy) b1.grid(row=7, column=2, ipadx=20, padx=20, pady=20, sticky="e") fen.mainloop()