Ответы
ПРИМЕЧАНИЕ автор не знает украинский язык. там где "!!!!" переписать то, что в кавычках "". и указать фамилию и имя в root.title(" ").
____________________________________________________
ПРИМІТКА автор не знає української мови. там де "!!!!" переписати те, що в лапках " ". та вказати прізвище та ім'я в root.title(" ").
________________________________________________________
from tkinter import *
ans = ''
def xyz(a,b):
return a*(4*b-4)
def get_ent(ent_1, ent_2):
a = int(ent_1.get())
b = int(ent_2.get())
destroy_tk()
tk(xyz(a,b))
def tk(ans):
global root
root=Tk()
root.title("Указать ФИО") #!!!!!!!!!!!!
w = root.winfo_screenwidth()
h = root.winfo_screenheight()
w = w//2 # середина экрана
h = h//2
w = w - 400 # смещение от середины
h = h - 350
root.geometry('400x300+{}+{}'.format(w, h))
root.resizable(False, False)
fr_1 = Frame(root)
lab_1 = Label(fr_1, text="Введите значения переменной a:", font=("Arial", 12)) #!!!!!!!!!!!!!!!!!!!!!!!
ent_1 = Entry(fr_1, width=30)
lab_2 = Label(fr_1, text="Введите значения переменной b:", font=("Arial", 12)) # !!!!!!!!!!!!!!!!!!!!
lab_3 = Label(fr_1, text="a * (4 * b - a) = " + str(ans), font=("Arial", 12))
ent_2 = Entry(fr_1, width=30)
but_1 = Button(fr_1, text='Вычислить', font=("Arial", 12), command=lambda:[get_ent(ent_1, ent_2)]) # !!!!!!!!!!!!!!!!!!!!!!!
fr_1.place(relx=0.5, rely=0.4, anchor="center")
lab_1.pack(padx=10, pady=10)
ent_1.pack(pady=10)
lab_2.pack(padx=10, pady=10)
ent_2.pack(pady=10)
lab_3.pack(padx=10, pady=10)
but_1.pack(pady=10)
root.mainloop()
def destroy_tk():
root.destroy()
tk(ans)
Ответ:
Привет. Вот код:
from tkinter import *
root=Tk()
root.title("Имя Фамилия")
root.geometry("400x300")
l1=Label(root, text='Введіть значення змінної а')
l2=Label(root, text='Введіть значення змінної b')
enter_a=Entry(root)
enter_b=Entry(root)
l3=Label(root,text='a*(4*b-a) = ')
def func():
try:
a=int(enter_a.get())
b=int(enter_b.get())
res=a*(4*b-a)
new_txt="a*(4*b-a) = "+str(res)
l3.config(text = new_txt)
except ValueError:
l3.config(text = "Невірне значення!")
b=Button(root,text='Далі', command=func)
l1.place(relx=.5,rely=.1, anchor="center")
enter_a.place(relx=.5,rely=.2, anchor="center")
l2.place(relx=.5,rely=.3, anchor="center")
enter_b.place(relx=.5,rely=.4, anchor="center")
b.place(relx=.5,rely=.5, anchor="center")
l3.place(relx=.5,rely=.6, anchor="center")
root.mainloop()
В функции func можешь убрать try и except, это я уже от себя добавил. Если че непонятно, пиши, поменяю
Объяснение: