import tkinter as tk
from tkinter import ttk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import numpy as np
def graf():
fig = Figure(figsize=(5, 4), dpi=100)
t = np.arange(-3, 3, .01)
a = eval(entry1.get())
b = eval(entry2.get())
c = eval(entry3.get())
fig.add_gridspec(True)
fig.add_subplot(111).plot(t, a*t**2+b*t+c,'o:g')
canvas = FigureCanvasTkAgg(fig, master=root)
canvas.draw()
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
if __name__ == '__main__':
# Ventana principal
root = tk.Tk()
root.title("Graficar Funcion")
root.geometry("700x700")
# Coheficiente 1
dato1=tk.StringVar()
entry1=ttk.Entry(root, textvariable=dato1, width=5)
entry1.place(x=5, y=5)
lblCo1 = tk.Label(root,text="X^2 +")
lblCo1.place(x=45,y=5)
# Coheficiente 2
dato2=tk.StringVar()
entry2=ttk.Entry(root, textvariable=dato2, width=5)
entry2.place(x=100, y=5)
lblCo2 = tk.Label(root,text="X +")
lblCo2.place(x=150,y=5)
# Coheficiente 3
dato3=tk.StringVar()
entry3=ttk.Entry(root, textvariable=dato3, width=5)
entry3.place(x=200, y=5)
# Boton
button = tk.Button(root, text="Graficar", command=graf)
button.pack()
# Iniciar el bucle principal de la aplicación
root.mainloop()
download source code
No hay comentarios:
Publicar un comentario