from tkinter import *
root = Tk()
root.title("Formação de Preço")
root.geometry("400x500")
root.resizable(0,0)
root.config(bg="#d9ead3")
def app(*args):
ci =custo_produto.get()
m =margem_lucro.get()
mp = m/100
r = radio.get()
valor_sem_Iva = ci*mp+ci
valor_iva = valor_sem_Iva*r
if r == 0:
pf = ci + ci*mp
else:
a =(ci+ci*mp)*(1+r)
pf = round(a,2)
resultado.set(pf),resultado_sem_Iva.set(valor_sem_Iva),resultadoIva.set(valor_iva)
def limpar():
custo_produto_entrada.delete(0, END)
margem_lucro_entrada.delete(0, END)
titulo = Label(text="Formação de preço de um produto ",bg="#d9ead3",fg="#0b5394",
font=("Arial","15","bold"))
titulo.place(relx=0.1,rely=0.05)
custo_inicial = Label(text="Custo Inicial: ",bg="#d9ead3",fg="#0b5394",
font=("Arial","13","bold"))
custo_inicial.place(relx=0.28,rely=0.15)
custo_produto = DoubleVar()
custo_produto_entrada= Entry(textvariable=custo_produto,
font=("Arial","12","bold"),
bg="white",fg="blue",justify='center')
custo_produto_entrada.place(relx=0.65,rely=0.15,relwidth=0.2)
margem_lucro_texto = Label(text="Margem de lucro (em %): ",bg="#d9ead3",fg="#0b5394",
font=("Arial","13","bold"))
margem_lucro_texto.place(relx=0.05,rely=0.25)
margem_lucro = DoubleVar()
margem_lucro_entrada= Entry(textvariable=margem_lucro,
font=("Arial","12","bold"),
bg="white",fg="blue",justify='center')
margem_lucro_entrada.place(relx=0.65,rely=0.25,relwidth=0.2)
radio = DoubleVar()
lblradio = Label(text="Percentagem do IVA ",
font=("Helvetica", '12',"bold"), bg="#d9ead3",fg='#0b5394')
lblradio.place(relx=0.3, rely=0.35)
R1 = Radiobutton( text="0%", variable=radio, value=0, bg="#d9ead3")
R1.place(relx=0.3, rely=0.43)
R2 = Radiobutton(text="6%", variable=radio, value=0.06, bg="#d9ead3")
R2.place(relx=0.4, rely=0.43)
R3 = Radiobutton(text="13%", variable=radio, value=0.13, bg="#d9ead3")
R3.place(relx=0.5, rely=0.43)
R4 = Radiobutton(text="23%", variable=radio, value=0.23, bg="#d9ead3")
R4.place(relx=0.6, rely=0.43)
but1 = Button( text="Calcular", bd=2, bg='#107db2', fg='white',
font=('verdana', 12, 'bold'),command=app)
but1.place(relx=0.3, rely=0.5, relwidth=0.2, 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.55, rely=0.5, relwidth=0.2, relheight=0.1)
resultado_texto =Label(text="Valor Final:",
font=("Arial",12,"bold"),bg="#d9ead3")
resultado_texto.place(relx=0.2,rely=0.85,relwidth=0.3)
resultado_texto_IVA =Label(text="Valor do IVA:",
font=("Arial",12,"bold"),bg="#d9ead3")
resultado_texto_IVA.place(relx=0.2,rely=0.65,relwidth=0.3)
resultado_texto_Total_sem_IVA =Label(text="Valor Total sem IVA:",
font=("Arial",12,"bold"),bg="#d9ead3")
resultado_texto_Total_sem_IVA.place(relx=0.05,rely=0.75,relwidth=0.4)
resultadoIva = StringVar()
resultadoIva_resultado =Label(textvariable=resultadoIva,
font=("Arial",12,"bold"),bg="#f0f8ff")
resultadoIva_resultado.place(relx=0.55,rely=0.65,relwidth=0.35)
resultado_sem_Iva = StringVar()
resultado_sem_Iva_resultado =Label(textvariable=resultado_sem_Iva,
font=("Arial",12,"bold"),bg="#f0f8ff")
resultado_sem_Iva_resultado.place(relx=0.55,rely=0.75,relwidth=0.35)
resultado = StringVar()
resulatdoresultado =Label(textvariable=resultado,
font=("Arial",12,"bold"),bg="#f0f8ff")
resulatdoresultado.place(relx=0.55,rely=0.85,relwidth=0.35)
margem_lucro_entrada.focus()
root.bind("<Return>", app)
root.mainloop()