Mundo em Python

Calcular Preço Venda

from tkinter import *
root = Tk()
root.geometry("700x500")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Calcular Preço Venda")
titulo = Label(text="Calcular preço Venda",
font=("Arial", "28", "bold"), bg="#103030", fg="#49e3e3")
titulo.place(relx=0.18, rely=0.05)
texto_sub1 = Label(text="Custo Produto:",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub1.place(relx=0.2, rely=0.2) texto_sub2 = Label(text="Margem lucro desejada:",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub2.place(relx=0.05, rely=0.31) texto_sub3 = Label(text="Outros Custos:",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub3.place(relx=0.19, rely=0.41) texto_sub4 = Label(text="Impostos (em %):",
font=("Arial", "18", "bold"), bg="#103030", fg="#49e3e3")
texto_sub4.place(relx=0.15, rely=0.51) # Entradas
Custo_Produto = StringVar()
Custo_Produto_entrada = Entry(textvariable=Custo_Produto,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Custo_Produto_entrada.place(relx=0.55, rely=0.21, relwidth=0.35)
Custo_Produto_entrada.focus() Margem_lucro = StringVar()
Margem_lucro_entrada = Entry(textvariable=Margem_lucro,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Margem_lucro_entrada.place(relx=0.55, rely=0.31, relwidth=0.35) Outros_Custos = StringVar()
Outros_Custos_entrada = Entry(textvariable=Outros_Custos,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Outros_Custos_entrada.place(relx=0.55, rely=0.41, relwidth=0.35) Impostos = StringVar()
Impostos_entrada = Entry(textvariable=Impostos,
font=("Arial", "12", "bold"),
bg="white", fg="blue", justify='center')
Impostos_entrada.place(relx=0.55, rely=0.52, relwidth=0.35)
def limpar():
Impostos_entrada.delete(0, END)
Outros_Custos_entrada.delete(0, END)
Custo_Produto_entrada.delete(0, END)
Margem_lucro_entrada.delete(0, END)
resultado_texto.config(text="") def app():
try:
t = float(Impostos.get())
outros_cus = float(Outros_Custos.get())
custos = float(Custo_Produto.get())
margem = float(Margem_lucro.get()) if custos < 0 or margem < 0 or outros_cus < 0 or t < 0:
raise ValueError("Todos os valores devem ser positivos.") lucro = custos * (margem / 100)
valor_impostos = (custos + outros_cus + lucro) * (t / 100)
preco_venda = custos + lucro + outros_cus + valor_impostos resultado_texto.config(text=f"Preço de Venda: € {preco_venda:.2f}")
except ValueError:
resultado_texto.config(text="Valor digitado inválido!!") 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) 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) root.mainloop()
0