Calcular o preço final de um produto

Sem Título.png


import tkinter

class compintapp_tk(tkinter.Tk):
def __init__(self,parent):
tkinter.Tk.__init__(self,parent)
self.parent = parent
self.initialize()

def initialize(self):
self.grid()
## Title ---------------------------------------
titlelbl = tkinter.Label(self, text="Calcular o "
"Preço Final",
anchor="center",fg="white"
,bg="blue")
titlelbl.grid(column=0,row=0,columnspan=3,
sticky='EW')
## End Title & subtitle labels ---------------------------------------

## Input Labels --------------------------------------------------
cprodutolbl = tkinter.Label(self, text="Custo do"
" Produto :",
anchor="w",fg="white",
bg="SlateGray4")
cprodutolbl.grid(column=0,row=1,columnspan=1,
sticky='EW')

taxalbl = tkinter.Label(self, text="Taxa de Margem "
"de Venda (em %):",
anchor="w",fg="white"
,bg="SlateGray4")
taxalbl.grid(column=0,row=2,columnspan=1
,sticky='EW')

pfinallbl = tkinter.Label(self, text="Preço Final:",
anchor="w",fg="white",
bg="SlateGray4")
pfinallbl.grid(column=0,row=4,columnspan=1,
sticky='EW')

## end of input labels ------------------------------------------------
## Input Boxes --------------------------------------------------------

self.cp = tkinter.DoubleVar()
cproduto = tkinter.Entry(self,textvariable=self.cp)
cproduto.grid(column=1,row=1, sticky='EW')

self.txm = tkinter.DoubleVar()
taxa = tkinter.Entry(self,textvariable=self.txm)
taxa.grid(column=1,row=2, sticky='EW')

## end of input boxes -------------------------------------------------
## Button
button = tkinter.Button(self,text="Calcular",
command=self.OnButtonClick)
button.grid(column=0,row=3,columnspan=3)
## end of button

## Output labels
self.pfinal = tkinter.StringVar()
prodfinal = tkinter.Label(self,
textvariable=self.pfinal,
anchor="e",fg="red",
bg="yellow")
prodfinal.grid(column=1,row=4,columnspan=2,
sticky='EW')

## end of output labels -----------------------------------------------

self.grid_columnconfigure(0,weight=1)
self.resizable(True,False)

def OnButtonClick(self):
p = self.cp.get()
i = self.txm.get()
t=(i/100)
## Compound Interest Calculation
prodfinal = round((p/(1-t)),2)
self.pfinal.set(prodfinal)

if __name__ == "__main__":
app = compintapp_tk(None)
app.title('Calcular o Preço Final')
app.mainloop()

 

Comentários

Mensagens populares deste blogue

Criar Cartões de Visita

12 signos egípcios

Calcular a percentagem de ocupação