Preço por Unidade

from tkinter import *

root = Tk()
root.geometry("700x400")
root.resizable(0, 0)
root.config(bg="#103030")
root.title("Preço por Unidade")
titulo = Label(
text="Preço por Unidade",
font=("Arial", 28, "bold"),
bg="#103030",
fg="#49e3e3"
)
titulo.place(relx=0.25, rely=0.05)
texto_sub1 = Label(
text="Preço Total (com IVA):",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub1.place(relx=0.15, rely=0.25)

Preço_Total = StringVar()
Preço_Total_entrada = Entry(
textvariable=Preço_Total,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify='center'
)
Preço_Total_entrada.place(relx=0.55, rely=0.26, relwidth=0.25)
Preço_Total_entrada.focus()
texto_sub2 = Label(
text="Unidades:",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub2.place(relx=0.2, rely=0.4)

Unidades = StringVar()
Unidades_entrada = Entry(
textvariable=Unidades,
font=("Arial", 12, "bold"),
bg="white",
fg="blue",
justify='center'
)
Unidades_entrada.place(relx=0.55, rely=0.41, relwidth=0.25)
texto_sub3 = Label(
text="IVA:",
font=("Arial", 18, "bold"),
bg="#103030",
fg="#49e3e3"
)
texto_sub3.place(relx=0.2, rely=0.5)

var = StringVar()
dropDownList = ["0%", "6%", "13%", "23%"]

def app(*args):
try:
unidades = int(Unidades.get())
total_com_iva = float(Preço_Total.get())
iva_percent = int(var.get().replace("%", ""))

if unidades == 0:
raise ZeroDivisionError

# Remover IVA do total
total_sem_iva = total_com_iva / (1 + iva_percent / 100)

# Preço unitário sem IVA
preco_unitario_sem_iva = total_sem_iva / unidades

resultado_texto.config(
text=f"Preço unitário (sem IVA): {preco_unitario_sem_iva:.2f} €"
)

except ValueError:
resultado_texto.config(text="Insira valores numéricos válidos!")
except ZeroDivisionError:
resultado_texto.config(text="Unidades não pode ser 0!")

def limpar():
Preço_Total_entrada.delete(0, END)
Unidades_entrada.delete(0, END)
resultado_texto.config(text="")
dropdown = OptionMenu(root, var, *dropDownList, command=app)
var.set(dropDownList[0])
dropdown.place(relx=0.55, rely=0.5, relwidth=0.25)
dropdown.config(
background='#09A3BA',
foreground="#FFFFFF",
font=("Arial", 14, "bold")
)
dropdown["menu"].config(
background='#09A3BA',
foreground="#FFFFFF",
font=("Arial", 14, "bold")
)
resultado_texto = Label(
text="",
font=("Arial", 14, "bold"),
bg="#cfe2f3"
)
resultado_texto.place(relx=0.05, rely=0.8, relwidth=0.9, relheight=0.12)
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)

root.mainloop()



Comentários

Mensagens populares deste blogue

Criar Cartões de Visita

12 signos egípcios

Calcular a percentagem de ocupação