Графика Tkinter Python
Хочется узнать какая строчка лучше всего подойдет моей программе чтобы ответы двух программ сразу же выводились в графический интерфейс, а не в самом Python'е.
from math import *
from tkinter import *
window = Tk()
window.title("Проектная работа")
window.geometry("400x120")
topFrame = Frame(window)
bottomFrame = Frame(window)
topFrame.pack()
bottomFrame.pack()
def clicked1():
a, b, e = -4.0, -1.2, 0.0001
def f(value):
return exp(value) + value ** 2 - 2
x = (a + b) / 2
y1 = f(a)
y3 = f(x)
while abs(y3) > e:
x = (a + b) / 2
y3 = f(x)
if y1 * y3 < 0:
b = x
else:
a = x
print(f'x = {x}')
def clicked2():
import math
def sign(x):
return bool(x > 0) - bool(x < 0)
def f(value):
return math.exp(value) + value ** 2 - 2
old = -4
new = -1.2
f_old = f(old)
f_new = f(new)
while True:
tmp = (old + new) / 2
f_tmp = f(tmp)
if abs(tmp - old) < 0.0000001:
break
if sign(f_tmp) == sign(f_old):
old, f_old = tmp, f_tmp
else:
new, f_new = tmp, f_tmp
print("x = ", (old + new) / 2)
text2 = Label(window, text = "Уравнение: e^x+x^2-2=0")
text1 = Label(window, text = "Диапазон: [-4; -1.2] ")
button1 = Button(bottomFrame, text = "Метод прямого перебора" , fg = "red", command = clicked1 )
button2 = Button(bottomFrame, text = "Метод дихотомии" , fg = "red", command = clicked2 )
entry_text = Entry(window)
text2.pack()
text1.pack()
entry_text.pack()
button1.pack(side = LEFT)
button2.pack(side = LEFT)
window.mainloop()