Mundo em Python

Calcule o número de Latas Cheias

lata_ml = 330
from tkinter import *
root = Tk()
root.geometry("700x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Calcule o número de Latas Cheias")
titulo = Label(
text="Calcule o número de Latas Cheias",font=("Arial", 28, "bold"),bg="#103030",fg="#49e3e3")
titulo.place(relx=0.05, rely=0.05) texto_sub1 = Label(
text="Volume em litros:",font=("Arial", 25, "bold"),bg="#103030",fg="#49e3e3")
texto_sub1.place(relx=0.05, rely=0.3) Volume_litros = StringVar()
Volume_litros_entrada = Entry(
textvariable=Volume_litros,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify='center'
)
Volume_litros_entrada.place(relx=0.49, rely=0.33, relwidth=0.45)
Volume_litros_entrada.focus()
def limpar():
Volume_litros_entrada.delete(0, END)
resultado_texto.config(text="") def app():
try:
litros = float(Volume_litros.get())
volume_ml = litros * 1000
numero_latas = volume_ml / lata_ml
latas_cheias = int(numero_latas)
resto = numero_latas - latas_cheias
percentual_resto = resto * 100
if resto == 0:
mensagem = f"Número de latas necessárias: {numero_latas:.2f}\nLatas cheias: {latas_cheias}\nNão há próxima lata a preencher."
else:
mensagem = f"Número de latas necessárias: {numero_latas:.2f}\nLatas cheias: {latas_cheias}\n" \
f"Próxima lata preenchida: {percentual_resto:.0f}%"
resultado_texto.config(text=mensagem) except ValueError:
resultado_texto.config(text="Por favor, insira valores numéricos válidos.") # 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.5, 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.5, 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.5, relwidth=0.25, relheight=0.1) resultado_texto = Label(
text="",
font=("Arial", 12, "bold"),
bg="#cfe2f3"
)
resultado_texto.place(relx=0.05, rely=0.63, relwidth=0.9, relheight=0.3)
root.mainloop()
0