Mundo em Python

Cilindro

from tkinter import *
import math root = Tk()
root.geometry("400x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Cilindro") titulo = Label(text="Cilindro",
font=("Arial", "45", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.18, rely=0.05) texto_sub1 = Label(text="Altura:",
font=("Arial", "25", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.1, rely=0.25)
altura = StringVar()
altura_entrada = Entry(textvariable=altura,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
altura_entrada.place(relx=0.5, rely=0.27, relwidth=0.35)
altura_entrada.focus() texto_sub2 = Label(text="Raio:",
font=("Arial", "25", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.1, rely=0.4)
raio = StringVar()
raio_entrada = Entry(textvariable=raio,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
raio_entrada.place(relx=0.5, rely=0.43, relwidth=0.35)
def limpar():
raio_entrada.delete(0, END)
altura_entrada.delete(0, END)
resultado_texto.config(text="")
def app():
try:
r = float(raio.get())
h = float(altura.get()) # Cálculo da Área da Superfície Lateral
area_superficie_lateral = 2 * math.pi * r * h # Cálculo da Área Total da Superfície
area_total_superficie = 2 * math.pi * r * (r + h) # Cálculo do Volume
volume = math.pi * pow(r, 2) * h # Exibindo os resultados na interface
resultado_texto.config(text=f"Área da Superfície Lateral: {area_superficie_lateral:.2f}\n"
f"Área Total da Superfície: {area_total_superficie:.2f}\n"
f"Volume do Cilindro: {volume:.2f}") except ValueError:
resultado_texto.config(text="Por favor, insira valores válidos para raio e altura.")
but1 = Button(text="Mostrar", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.1, rely=0.53, 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.53, 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.53, relwidth=0.25, relheight=0.1) resultado_texto = Label(font=("Arial", 12, "bold"), bg="#cfe2f3")
resultado_texto.place(relx=0.05, rely=0.68, relwidth=0.9, relheight=0.3) root.mainloop()
0