Tkinter получить значение из entry для построения графика

maxi994

Новичок
Пользователь
Авг 28, 2020
1
0
1
Не могу построить график после ввода. в чеем проблема?

from tkinter import *
from docxtpl import DocxTemplate
import numpy as np
from scipy.interpolate import BSpline, UnivariateSpline, Akima1DInterpolator, PchipInterpolator
import matplotlib.pyplot as plt

root = Tk()
root.geometry("1080x600")

e = StringVar()

u0 = StringVar()
u1 = StringVar()
u2 = StringVar()
u3 = StringVar()
u4 = StringVar()
u5 = StringVar()
u6 = StringVar()
u7 = StringVar()
u8 = StringVar()

# Creating a Label Widget
myLabel1 = Label(root, borderwidth=1, text="Hello World!").grid(row=0, column=0)
e_entry = Entry(root, relief=RAISED, borderwidth=1, textvariable = e).grid(row=0, column=3)
x_data0 = Label(root, borderwidth=1, text="I, А").grid(row=2, column=0)
y_data0 = Label(root, borderwidth=1, text="U, В").grid(row=3, column=0)

i0 = Label(root, borderwidth=1, text="0").grid(row=2, column=1)
i1 = Label(root, borderwidth=1, text="0.005").grid(row=2, column=2)
i2 = Label(root, borderwidth=1, text="0.01").grid(row=2, column=3)
i3 = Label(root, borderwidth=1, text="0.1").grid(row=2, column=4)
i4 = Label(root, borderwidth=1, text="0.2").grid(row=2, column=5)
i5 = Label(root, borderwidth=1, text="0.3").grid(row=2, column=6)
i6 = Label(root, borderwidth=1, text="0.5").grid(row=2, column=7)
i7 = Label(root, borderwidth=1, text="0.7").grid(row=2, column=8)
i8 = Label(root, borderwidth=1, text="1").grid(row=2, column=9)

e = Label(root, borderwidth=1, text="u0").grid(row=3, column=1)
u0_e = Entry(root, relief=RAISED, borderwidth=1, textvariable = u0)
u0_e.grid(row=3, column=2)

u1_e = Entry(root, relief=RAISED, borderwidth=1)
u1_e.grid(row=3, column=2)

u2_e = Entry(root, relief=RAISED, borderwidth=1)
u2_e.grid(row=3, column=3)

u3_e = Entry(root, relief=RAISED, borderwidth=1)
u3_e.grid(row=3, column=4)

u4_e = Entry(root, relief=RAISED, borderwidth=1,)
u4_e.grid(row=3, column=5)

u5_e = Entry(root, relief=RAISED, borderwidth=1)
u5_e.grid(row=3, column=6)

u6_e = Entry(root, relief=RAISED, borderwidth=1)
u6_e.grid(row=3, column=7)

u7_e = Entry(root, relief=RAISED, borderwidth=1)
u7_e.grid(row=3, column=8)

u8_e = Entry(root, relief=RAISED, borderwidth=1)
u8_e.grid(row=3, column=9)

def myClick ():
tpl = DocxTemplate ('template.docx')
context = {
'e': e.get()
}
tpl.render(context)
tpl.add_picture('BAX.png')
tpl.save('dynamic_table.docx')

def myClick_1 ():
plt.show()


def multiply_by(value, by):
return value * by

def GetData(event):
u1_getfl = float(u1_e.get())
u2_getfl = float(u2_e.get())
u3_getfl = float(u3_e.get())
u4_getfl = float(u4_e.get())
u5_getfl = float(u5_e.get())
u6_getfl = float(u6_e.get())
u7_getfl = float(u7_e.get())
u8_getfl = float(u8_e.get())
print(float(u1_e.get()))

def plotXY(event):
GetData(event)
u1_getfl = float(u1_e.get())
u2_getfl = float(u2_e.get())
u3_getfl = float(u3_e.get())
u4_getfl = float(u4_e.get())
u5_getfl = float(u5_e.get())
u6_getfl = float(u6_e.get())
u7_getfl = float(u7_e.get())
u8_getfl = float(u8_e.get())

x_data = np.array([0, 0.005, 0.01, 0.1, 0.2, 0.3, 0.5, 0.7, 1])
y_d = (0, u1_getfl(), u3_getfl(), u3_getfl(), u4_getfl(), u5_getfl(), u6_getfl(), u7getfl(), u8_getfl())

y_data = np.append(y_d)

x_data_smooth = np.linspace(min(x_data), max(x_data), 1000)
fig, ax = plt.subplots(1,1)

bi = PchipInterpolator(x_data, y_data)
y_data_smooth = bi(x_data_smooth)
ax.plot(x_data_smooth, y_data_smooth, 'b')

ax.plot(x_data_smooth, y_data_smooth)
ax.scatter(x_data, y_data)

plt.title('График намагничивания')
plt.ylabel('U, В')
plt.xlabel('I, мА')
plt.grid(True)
plt.savefig('BAX.png', bbox_inches = 'tight')
plt.show()

myButton_2 = Button(root, text="gcnhjvnm!")
myButton_2.grid(row=6, column=8)
myButton_2.bind("<Button-1>", plotXY)

myButton_1 = Button(root, text="Показать график!")
myButton_1.grid(row=0, column=8)
myButton_1.bind("<Button-1>", GetData)

root.mainloop()
 

Форум IT Специалистов