Área de uma coroa circular

from tkinter import *
import math

# Configuração da janela
root = Tk()
root.geometry("600x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Área de uma coroa circular")

# Título
titulo = Label(text="Área de uma coroa circular",
font=("Arial", "28", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.1, rely=0.05)

# Subtítulos
texto_sub1 = Label(text="Raio maior:",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.2, rely=0.25)

texto_sub2 = Label(text="Raio menor:",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.2, rely=0.45)

# Entradas
Raio_maior = StringVar()
Raio_maior_entrada = Entry(textvariable=Raio_maior,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Raio_maior_entrada.place(relx=0.55, rely=0.26, relwidth=0.27)
Raio_maior_entrada.focus()

Raio_menor = StringVar()
Raio_menor_entrada = Entry(textvariable=Raio_menor,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Raio_menor_entrada.place(relx=0.55, rely=0.46, relwidth=0.27)


# Funções
def limpar():
Raio_menor_entrada.delete(0, END)
Raio_maior_entrada.delete(0, END)
resultado_texto.config(text="")


def app():
try:
# Obtendo os valores dos raios
raio_externo = float(Raio_maior.get())
raio_interno = float(Raio_menor.get())

# Validando os raios
if raio_externo <= raio_interno:
raise ValueError("O raio externo deve ser maior que o raio interno.")

# Calculando a área
area = math.pi * (raio_externo ** 2 - raio_interno ** 2)

# Exibindo o resultado
mensagem = f"A área da coroa circular é: {area:.2f}"
resultado_texto.config(text=mensagem)
except ValueError as e:
resultado_texto.config(text=str(e))
except Exception:
resultado_texto.config(text="Erro: verifique os valores inseridos.")


# Botões
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
resultado_texto = Label(text="",
font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.15)

# Loop principal
root.mainloop()

Comentários

Mensagens populares deste blogue

Criar Cartões de Visita

12 signos egípcios

Calcular a percentagem de ocupação