-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappGUI.py
More file actions
92 lines (79 loc) · 3.33 KB
/
Copy pathappGUI.py
File metadata and controls
92 lines (79 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import tkinter as tk
from tkinter import ttk
from appBD import AppBD
class PrincipalBD:
def __init__(self, root, db):
self.root = root
self.db = db
self.root.title("Gestão de Produtos")
# Componentes da interface gráfica
self.lblCodigo = tk.Label(root, text="Código")
self.lblCodigo.grid(row=0, column=0)
self.txtCodigo = tk.Entry(root)
self.txtCodigo.grid(row=0, column=1)
self.lblNome = tk.Label(root, text="Nome")
self.lblNome.grid(row=1, column=0)
self.txtNome = tk.Entry(root)
self.txtNome.grid(row=1, column=1)
self.lblPreco = tk.Label(root, text="Preço")
self.lblPreco.grid(row=2, column=0)
self.txtPreco = tk.Entry(root)
self.txtPreco.grid(row=2, column=1)
self.btnCadastrar = tk.Button(root, text="Cadastrar", command=self.fCadastrarProduto)
self.btnCadastrar.grid(row=3, column=0)
self.btnAtualizar = tk.Button(root, text="Atualizar", command=self.fAtualizarProduto)
self.btnAtualizar.grid(row=3, column=1)
self.btnExcluir = tk.Button(root, text="Excluir", command=self.fExcluirProduto)
self.btnExcluir.grid(row=4, column=0)
self.btnLimpar = tk.Button(root, text="Limpar", command=self.fLimparTela)
self.btnLimpar.grid(row=4, column=1)
self.tree = ttk.Treeview(root, columns=("CODIGO", "NOME", "PRECO"), show='headings')
self.tree.heading("CODIGO", text="Código")
self.tree.heading("NOME", text="Nome")
self.tree.heading("PRECO", text="Preço")
self.tree.grid(row=5, column=0, columnspan=2)
self.tree.bind('<ButtonRelease-1>', self.apresentarRegistrosSelecionados)
self.carregarDadosIniciais()
def fCadastrarProduto(self):
codigo = self.txtCodigo.get()
nome = self.txtNome.get()
preco = self.txtPreco.get()
self.db.inserir_dados(nome, preco)
self.tree.insert("", "end", values=(codigo, nome, preco))
self.fLimparTela()
def fAtualizarProduto(self):
codigo = self.txtCodigo.get()
nome = self.txtNome.get()
preco = self.txtPreco.get()
self.db.atualizar_dados(codigo, nome, preco)
self.fLimparTela()
self.carregarDadosIniciais()
def fExcluirProduto(self):
codigo = self.txtCodigo.get()
self.db.excluir_dados(codigo)
self.fLimparTela()
self.carregarDadosIniciais()
def fLimparTela(self):
self.txtCodigo.delete(0, tk.END)
self.txtNome.delete(0, tk.END)
self.txtPreco.delete(0, tk.END)
def apresentarRegistrosSelecionados(self, event):
item = self.tree.selection()[0]
valores = self.tree.item(item, "values")
self.txtCodigo.delete(0, tk.END)
self.txtCodigo.insert(tk.END, valores[0])
self.txtNome.delete(0, tk.END)
self.txtNome.insert(tk.END, valores[1])
self.txtPreco.delete(0, tk.END)
self.txtPreco.insert(tk.END, valores[2])
def carregarDadosIniciais(self):
for item in self.tree.get_children():
self.tree.delete(item)
registros = self.db.selecionar_dados()
for registro in registros:
self.tree.insert("", "end", values=registro)
# Criando a interface gráfica
root = tk.Tk()
app_bd = AppBD()
app_gui = PrincipalBD(root, app_bd)
root.mainloop()