from tkinter import *
# Create the main application window
root = Tk()
root.geometry("500x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Market Share")
# Title label
titulo = Label(text="Market Share",
font=("Arial", "30", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.25, rely=0.05)
# Sub-labels
texto_sub1 = Label(text="Vendas da Empresa:",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.17, rely=0.25)
texto_sub2 = Label(text="Vendas Totais do Mercado:",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.04, rely=0.45)
# Input fields
Vendas_Empresa = StringVar()
Vendas_Empresa_entrada = Entry(textvariable=Vendas_Empresa,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Vendas_Empresa_entrada.place(relx=0.7, rely=0.26, relwidth=0.25)
Vendas_Totais_Mercado = StringVar()
Vendas_Totais_Mercado_entrada = Entry(textvariable=Vendas_Totais_Mercado,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Vendas_Totais_Mercado_entrada.place(relx=0.7, rely=0.46, relwidth=0.25)
# Function to clear input fields and result label
def limpar():
Vendas_Empresa_entrada.delete(0, END)
Vendas_Totais_Mercado_entrada.delete(0, END)
resultado_texto.config(text="")
# Function to calculate market share
def app():
try:
empresa = float(Vendas_Empresa.get())
Vendas_Totais= float(Vendas_Totais_Mercado.get())
MarketShare = (empresa / Vendas_Totais) * 100
mensagem = f"Quota da empresa: {round(MarketShare, 2)} %"
resultado_texto.config(text=mensagem)
except ValueError:
resultado_texto.config(text="Valor digitado inválido!")
# Buttons for calculations and actions
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)
# Label for displaying results
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)
# Start the main loop of the application
root.mainloop()
Comentários
Enviar um comentário