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
| import numpy as np
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import (
FigureCanvasTkAgg, NavigationToolbar2Tk)
from tkinter import *
#a,b,c=0,0,0
def TracerGraphique(*args):
a=int(args[0])
b=int(args[1])
c=int(args[2])
canv=args[3]
#fig = Figure(figsize=(5, 4), dpi=100)
fig=Figure(figsize=(3,2), dpi=100)
ax=fig.add_subplot(111)
x=np.linspace(-10, 10, 200)
ax.plot(x, a*x**2+b*x+c)
canv=FigureCanvasTkAgg(fig, master=canv)
canv.draw()
#rightCanv.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
canv.get_tk_widget().grid(row=1)
fenetre=Tk()
fenetre.title("Polynome Second degré")
fenetre.geometry("700x250+150+50")
leftCanv = Canvas(fenetre, bg="blue", height=250, width=350)
leftCanv.pack(side=LEFT)
rightCanv = Canvas(fenetre, bg="yellow", height=250, width=350)
rightCanv.pack(side=RIGHT)
''' enlever tout ça, c'est du pastiche
rightCanv = Canvas(fenetre, bg="yellow", height=250, width=350)
rightCanv.pack(side=RIGHT)
fig = Figure(figsize=(5, 4), dpi=100)
x = np.linspace(-10, 10, 200)
fig.add_subplot(111).plot(x, a*x**2+b*x+c)
rightCanv = FigureCanvasTkAgg(fig, master=fenetre) # A tk.DrawingArea.
rightCanv.draw()
rightCanv.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
'''
coef1=Label(leftCanv, text="donner coef x²: ", bg='yellow', fg='blue') #Affiche un text
coef2=Label(leftCanv, text="donner coef x: ", bg='yellow', fg='blue')
coef3=Label(leftCanv, text="Valeur de c : ", bg='yellow', fg='blue')
coef1.place(x=10, y=20)
coef2.place(x=10, y=50)
coef3.place(x=10, y=80)
entryCoef1=Entry(leftCanv)
entryCoef2=Entry(leftCanv)
entryCoef3=Entry(leftCanv)
entryCoef1.place(x=140, y=20)
entryCoef2.place(x=140, y=50)
entryCoef3.place(x=140, y=80)
#boutonTracerGraphique=Button(leftCanv, text="Tracer graphique", font=("courrier",25), bg='yellow', fg='blue', command=TracerGraphique)
boutonTracerGraphique=Button(leftCanv, text="Tracer graphique",
font=("courrier",25), bg='yellow',
fg='blue',
command=lambda: TracerGraphique(entryCoef1.get(), entryCoef2.get(), entryCoef3.get(), rightCanv)
)
boutonTracerGraphique.place(x=10, y=170)
fenetre.mainloop() |