Mundo em Python

Participação de Mercado

from tkinter import *
root = Tk()
root.geometry("400x400")
root.resizable(0, 0)
root.config(bg="#5373a6")
root.title("Participação de Mercado")
titulo = Label(text="Participação de Mercado",
font=("Arial", "25", "bold"),bg="#5373a6",fg="#c5ede7")
titulo.place(relx=0.02, rely=0.05)
texto_sub1 = Label(text="Audiência do Programa:",
font=("Arial", "12", "bold"),bg="#5373a6",fg="#c5ede7")
texto_sub1.place(relx=0.03, rely=0.25) texto_sub2= Label(text="Audiência Total:",
font=("Arial", "12", "bold"),bg="#5373a6",fg="#c5ede7")
texto_sub2.place(relx=0.15, rely=0.4) Audiência_Programa = DoubleVar()
Audiência_Programa_entrada = Entry(textvariable=Audiência_Programa,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Audiência_Programa_entrada.place(relx=0.5, rely=0.25, relwidth=0.35) Audiência_Total = DoubleVar()
Audiência_Total_entrada = Entry(textvariable=Audiência_Total,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Audiência_Total_entrada.place(relx=0.5, rely=0.4, relwidth=0.35)
def app():
try:
at = Audiência_Total.get()
ap = Audiência_Programa.get()
Participação_Mercado = (ap/ at) *100
Participação_Mercadoarr = round(Participação_Mercado,2)
mensagem = f"A Participação de Mercado de {Participação_Mercadoarr} %."
except ZeroDivisionError:
mensagem = "Erro: A receita não pode ser zero."
except ValueError:
mensagem ="Erro: Insira valores válidos (números)."
resultado.set(mensagem)
def limpar():
Audiência_Programa_entrada.delete(0, END)
Audiência_Total_entrada.delete(0, END)
resultado.set("")
but1 = Button(text="Calcular", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'), command=app)
but1.place(relx=0.05, rely=0.6, 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.35, rely=0.6, 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.65, rely=0.6, 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