from tkinter import *
from tkinter import ttk
root=Tk()
class registadora():
def __init__(self):
self.root = root
self.janela()
self.frames_da_janela()
self.estrutura()
root.mainloop()
def janela(self):
self.root.title("Caixa Registadora")
self.root.configure(background='#1e3743')
self.root.geometry("750x600")
self.root.resizable(False, False)
def frames_da_janela(self):
self.frame_1 = Frame(self.root, bd=4, bg='#dfe3ee',
highlightbackground='#759fe6',
highlightthickness=2)
self.frame_1.place(relx=0.02, rely=0.02,
relwidth=0.96, relheight=0.96)
def estrutura(self):
self.produtos = ("Bolachas-$5", "Rebuçados-$3",
"Gomas-$2", "Chocolate-$4", "Batatas Fritas-$6",
"Bolos-$1")
self.quantidade = IntVar()
self.caixaTotal = IntVar()
self.total = 0
self.selecionar_produtos=Label(self.root, text="Selecionar o Produto: ",
bg='#dfe3ee')
self.selecionar_produtos.place(relx=0.1,rely=0.1)
self.selecionar_quantidade=Label(self.root, text="Quantidade: "
,bg='#dfe3ee')
self.selecionar_quantidade.place(relx=0.1,rely=0.2)
self.texto_total=Label(self.root, text="Total: ",bg='#dfe3ee')
self.texto_total.place(relx=0.65,rely=0.85)
self.combo = ttk.Combobox(self.root, state="readonly")
self.combo.place(relx=0.3,rely=0.1)
self.combo["values"] = self.produtos
self.combo.current(0)
self.quantidade_entrada= Entry(self.root, textvariable=self.quantidade)
self.quantidade_entrada.place(relx=0.3,rely=0.2)
self.total_entrada = Entry(self.root, textvariable=self.caixaTotal)
self.total_entrada.place(relx=0.8,rely=0.85)
# command=self.butaoclick
self.butao =Button(self.root, text="Adicionar",command=self.butaoclick)
self.butao.place(relx=0.1,rely=0.3)
self.tabla = ttk.Treeview(self.root, columns=("Quantidade", "Subtotal"))
self.tabla.heading("#0", text="Produto")
self.tabla.heading("Quantidade", text="Quantidade")
self.tabla.heading("Subtotal", text="Subtotal")
self.tabla.place(relx=0.1,rely=0.4)
def butaoclick(self):
texto2 = self.combo.get()
dados = texto2.split("-$")
produto_buta = dados[0]
preco_buta = dados[1]
quantidade_butao = self.quantidade.get()
subtotal_butao = int(preco_buta) * int(quantidade_butao)
self.tabla.insert("", END, text=produto_buta,
values=(quantidade_butao, "$" + str(subtotal_butao)))
self.total = self.total + subtotal_butao
self.caixaTotal.set("$" + str(self.total))
registadora()