from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import numpy
from tkinter import *
import tkinter as tk
import matplotlib.pyplot as plt
import matplotlib
from tkinter import messagebox
def grah():
fig, ax = plt.subplots(1)
fig.clf()
fig, ax = plt.subplots(1)
for label in ax.xaxis.get_ticklabels():
label.set_fontsize(0)
for label in ax.yaxis.get_ticklabels():
label.set_fontsize(0)
plt.tick_params(length = 0, width = 0)
plt.plot([0,0], [0,0], color='white')
plt.plot([-0.25,0.25], [100,100], color='green', linewidth = 3)
plt.plot([-0.25,0.25], [0,0], color='green', linewidth = 3)
plt.bar(0, percent, color='red', width = 0.5, bottom = 0)
fig = matplotlib.pyplot.gcf()
fig.set_size_inches(1, 5)
canvas = FigureCanvasTkAgg(fig, master=root)
plt_widget = canvas.get_tk_widget()
plt_widget.place(x=120, y=1)
def procent():
global percent
outmin = float(OutputMin.get())
outmax = float(OutputMax.get())
if outmax > outmin:
scale = outmax - outmin
percent = round(((rez - outmin )* 100)/scale, 2)
percentstr = str(percent) + ' %'
textproc = Label(root, bg = "grey", fg = "red", justify = CENTER, width=11, font=("Ubunte", 14), text=percentstr)
textproc.place(x=1, y=220)
grah()
else:
scale = outmin - outmax
percent = round(((outmin - rez )* 100)/scale, 2)
percentstr = str(percent) + ' %'
textproc = Label(root, bg = "grey", fg = "red", justify = CENTER, width=11, font=("Ubunte", 14), text=percentstr)
textproc.place(x=1, y=220)
grah()
def procent1():
global percent
rangemax = float(RangeMax.get())
rangemin = float(RangeMin.get())
if rangemax > rangemin:
scale = rangemax - rangemin
percent = round(((rez - rangemin )* 100)/scale, 2)
percentstr = str(percent) + ' %'
textproc1 = Label(root, bg = "grey", fg = "red", justify = CENTER, width=11, font=("Ubunte", 14), text=percentstr)
textproc1.place(x=1, y=220)
grah()
else:
scale = rangemin - rangemax
percent = round(((rangemin - rez )* 100)/scale, 2)
percentstr = str(percent) + ' %'
textproc1 = Label(root, bg = "grey", fg = "red", justify = CENTER, width=11, font=("Ubunte", 14), text=percentstr)
textproc1.place(x=1, y=220)
grah()
def reshenie():
global rez
outmin = OutputMin.get()
outmax = OutputMax.get()
rangemax = RangeMax.get()
rangemin = RangeMin.get()
try:
out = Output.get()
outmin = float(outmin)
outmax = float(outmax)
rangemax = float(rangemax)
rangemin = float(rangemin)
try:
out = float(out)
if outmin != outmax:
Value.delete(0, END)
Output.delete(0, END)
rez = round (rangemin + (out - outmin)*(rangemin-rangemax)/(outmin-outmax), 2)
Value.insert(1, rez)
procent1()
else:
messagebox.showerror("Ошибка", "Ошибка ввода данных")
except:
val = Value.get()
try:
val = float(val)
if outmin != outmax:
Output.delete(0, END)
Value.delete(0, END)
rez = round (outmin + (val - rangemin)*(outmin-outmax)/(rangemin-rangemax), 2)
Output.insert(0, rez)
procent()
else:
messagebox.showerror("Ошибка", "Ошибка ввода данных")
except ValueError:
messagebox.showerror("Ошибка", "Должно быть введено число")
except ValueError:
messagebox.showerror("Ошибка", "Должно быть введено число")
global OutputMax
global OutputMin
global Output
global Value
global RangeMax
global RangeMin
global root
matplotlib.use('TkAgg')
root = tk.Tk()
root.title("Пересчет")
root.geometry("221x500")
root.resizable(width=False, height=False)
root.configure(background = "grey")
fig, ax = plt.subplots(1)
for label in ax.xaxis.get_ticklabels():
label.set_color('white')
label.set_fontsize(1)
for label in ax.yaxis.get_ticklabels():
label.set_color('white')
label.set_fontsize(1)
plt.tick_params(length = 0, width = 0)
plt.bar(0, 0, bottom = 0) #bottom - откуда берет начало бар по оси Y
fig = matplotlib.pyplot.gcf()
fig.set_size_inches(1, 5)
canvas = FigureCanvasTkAgg(fig, master=root)
plt_widget = canvas.get_tk_widget()
TextOutMax = Label(root, bg = "grey", height=1, font=("Ubunte", 10), text="OUTPUT MAX")
TextOutMax.place(x=17, y=50)
OutputMax = Entry(root, bg = "grey", width=15, justify = CENTER)
OutputMax.place(x=15, y=70)
TextOutMin = Label(root, bg = "grey", height=1, font=("Ubunte", 10), text="OUTPUT MIN")
TextOutMin.place(x=17, y=90)
OutputMin = Entry(root, bg = "grey", width=15, justify = CENTER)
OutputMin.place(x=15, y=110)
TextOutput = Label(root, bg = "grey", height=1, font=("Ubunte", 10), text="OUTPUT")
TextOutput.place(x=17, y=130)
Output = Entry(root, bg = "grey", width=15, justify = CENTER)
Output.place(x=15, y=150)
TextRangeMax = Label(root, bg = "grey", height=1, font=("Ubunte", 10), text="RANGE MAX")
TextRangeMax.place(x=17, y=340)
RangeMax = Entry(root, bg = "grey", width=15, justify = CENTER)
RangeMax.place(x=15, y=360)
TextRangeMin = Label(root, bg = "grey", height=1, font=("Ubunte", 10), text="RANGE MIN")
TextRangeMin.place(x=17, y=380)
RangeMin = Entry(root, bg = "grey", width=15, justify = CENTER)
RangeMin.place(x=15, y=400)
TextValue = Label(root, bg = "grey", height=1, font=("Ubunte", 10), text="VALUE")
TextValue.place(x=17, y=300)
Value = Entry(root, bg = "grey", width=15, justify = CENTER,)
Value.place(x=15, y=320)
button1 = Button(root, bg = "grey", text="Решение", width=12, font=("Ubunte", 10), command=reshenie)
button1.place(x=5.5, y=455)
plt_widget.place(x=120, y=1)
root.mainloop()