Mundo em Python

Calcular Hipotenusa

from tkinter import *
import math
root = Tk()
root.geometry("400x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Calcular Hipotenusa")
titulo = Label(text="Calcular Hipotenusa",
font=("Arial", "28", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.05, rely=0.05) texto_sub1 = Label(text="Cateto 1 :",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.2, rely=0.32) texto_sub2 = Label(text="Cateto 2 :",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.2, rely=0.5)
Cateto1 = IntVar()
Cateto1_entrada = Entry(textvariable=Cateto1,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Cateto1_entrada.place(relx=0.55, rely=0.33, relwidth=0.35) Cateto2 = IntVar()
Cateto2_entrada = Entry(textvariable=Cateto2,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Cateto2_entrada.place(relx=0.55, rely=0.52, relwidth=0.35) def limpar():
Cateto1_entrada.delete(0, END)
Cateto2_entrada.delete(0, END)
resultado.set("")
def app():
c1 = Cateto1.get()
c2 = Cateto2.get()
hipotenusa = math.sqrt(c1 ** 2 + c2 ** 2)
mensagem = f"A hipotenusa é {round(hipotenusa,3)}."
resultado.set(mensagem)
but1 = Button(text="Calcular", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.65, relwidth=0.25, relheight=0.1) but_limpar = Button(text="Limpar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=limpar)
but_limpar.place(relx=0.4, rely=0.65, relwidth=0.25, relheight=0.1) but_sair = Button(text="Sair", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=root.destroy)
but_sair.place(relx=0.7, rely=0.65, relwidth=0.25, relheight=0.1) resultado = StringVar()
resultado_texto = Label(textvariable=resultado,
font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15)
root.mainloop()
0