Skip to content

Commit e54577c

Browse files
committed
initial deploy
1 parent 952849e commit e54577c

13 files changed

+245
-0
lines changed

TkinterCRUD

Whitespace-only changes.

TkinterCRUD.db

20 KB
Binary file not shown.

Tkinter_SQL.py

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
import tkinter.messagebox
2+
from tkinter import *
3+
import pyodbc
4+
5+
# Integração com Banco de Dados
6+
dados_conexao = ("Driver={SQLite3 ODBC Driver};"
7+
"Server=localhost;"
8+
"Database=TkinterCRUD.db")
9+
conexao = pyodbc.connect(dados_conexao)
10+
cursor = conexao.cursor()
11+
12+
13+
def btn_clicked0(): #procurar insumo
14+
# pegar a informação do campo nome_insumo (entry1)
15+
nome_insumo = entry1.get()
16+
17+
# buscar essa informação do insumo no banco de dados
18+
comando = f"""SELECT * from Insumos
19+
WHERE nome_insumo = '{nome_insumo}';
20+
"""
21+
cursor.execute(comando)
22+
# print(cursor.fetchall()) #[(1, 'garrafa', '31/12/2050', 1, 9375.0)]
23+
entry0.delete("1.0","end") #limpa a caixa de texto
24+
25+
# colocar na caixa de texto (entry0) as informações do insumo no banco de dados
26+
for linha in cursor.fetchall():
27+
texto = f"Item: {linha.nome_insumo}\nQuantidade: {linha.quantidade}\nLote:{linha.lote}\nValidade:{linha.data_validade}" #aqui conseguimos referenciar os nomes das colunas por eles vieram do cursor
28+
entry0.insert("1.0", texto)
29+
30+
entry1.delete("0", "end") # limpa o campo
31+
print("Procurar Insumo")
32+
33+
def btn_clicked1(): #deletar insumo
34+
# pegar a informação do campo nome_insumo (entry1)
35+
nome_insumo = entry1.get()
36+
37+
# buscar e deletar a informação do insumo no banco de dados
38+
comando = f"""DELETE from Insumos
39+
WHERE nome_insumo = '{nome_insumo}';
40+
"""
41+
cursor.execute(comando)
42+
cursor.commit()
43+
44+
# exibir uma mensagem que deletou o insumo no entry 0
45+
tkinter.messagebox.showinfo(title='Aviso uso excluído', message=f'{nome_insumo} foi excluído do Banco de Dados!')
46+
entry1.delete("0", "end") #limpa o campo
47+
print("Deletar Insumo")
48+
49+
def btn_clicked2(): #registrar uso insumo (consumir um insumo)
50+
# pegar a informação do campo nome_insumo (entry1)
51+
nome_insumo = entry1.get()
52+
53+
# pegar a informação do campo quantidade (entry4)
54+
qtde_usada = entry4.get()
55+
56+
# buscar o insumo pelo nome_insumo no banco de dados
57+
# diminuir a quantidade do insumo de acordo com a quantidade consumida
58+
comando = f"""UPDATE Insumos
59+
SET quantidade = quantidade - {qtde_usada}
60+
WHERE nome_insumo = '{nome_insumo}';
61+
"""
62+
cursor.execute(comando)
63+
cursor.commit()
64+
65+
# exibir uma mensagem dizendo quantas unidades ainda restam
66+
tkinter.messagebox.showinfo(title='Aviso uso insumo', message=f'{qtde_usada} unidades de {nome_insumo} foram usadas!')
67+
print("Usar Insumo")
68+
69+
def btn_clicked3(): #adicionar insumo
70+
# pegar todos os campos
71+
nome_insumo = entry1.get()
72+
data_validade = entry2.get()
73+
lote = entry3.get()
74+
quantidade = entry4.get()
75+
76+
# adicionar no banco de dados aquele insumo
77+
comando = f"""INSERT INTO Insumos (nome_insumo, data_validade, lote, quantidade)
78+
VALUES
79+
('{nome_insumo}', '{data_validade}', '{lote}', '{quantidade}')"""
80+
cursor.execute(comando)
81+
cursor.commit()
82+
tkinter.messagebox.showinfo(title='Aviso adicionar produto', message='Produto adicionado com sucesso!')
83+
84+
# limpando os campos
85+
entry1.delete("0","end")
86+
entry2.delete("0","end")
87+
entry3.delete("0","end")
88+
entry4.delete("0","end")
89+
print("Adicionar Insumo")
90+
91+
92+
# print(entry1.get()) #nome_insumo
93+
# print(entry2.get()) #data_validade
94+
# print(entry3.get()) #lote
95+
# print(entry4.get()) #quantidade
96+
97+
98+
window = Tk()
99+
100+
window.geometry("711x646")
101+
window.configure(bg = "#ffffff")
102+
canvas = Canvas(
103+
window,
104+
bg = "#ffffff",
105+
height = 646,
106+
width = 711,
107+
bd = 0,
108+
highlightthickness = 0,
109+
relief = "ridge")
110+
canvas.place(x = 0, y = 0)
111+
112+
background_img = PhotoImage(file = f"background.png")
113+
background = canvas.create_image(
114+
355.5, 323.0,
115+
image=background_img)
116+
117+
img0 = PhotoImage(file = f"img0.png")
118+
b0 = Button(
119+
image = img0,
120+
borderwidth = 0,
121+
highlightthickness = 0,
122+
command = btn_clicked0,
123+
relief = "flat")
124+
125+
b0.place(
126+
x = 479, y = 195,
127+
width = 178,
128+
height = 38)
129+
130+
img1 = PhotoImage(file = f"img1.png")
131+
b1 = Button(
132+
image = img1,
133+
borderwidth = 0,
134+
highlightthickness = 0,
135+
command = btn_clicked1,
136+
relief = "flat")
137+
138+
b1.place(
139+
x = 247, y = 197,
140+
width = 178,
141+
height = 36)
142+
143+
img2 = PhotoImage(file = f"img2.png")
144+
b2 = Button(
145+
image = img2,
146+
borderwidth = 0,
147+
highlightthickness = 0,
148+
command = btn_clicked2,
149+
relief = "flat")
150+
151+
b2.place(
152+
x = 479, y = 123,
153+
width = 178,
154+
height = 35)
155+
156+
img3 = PhotoImage(file = f"img3.png")
157+
b3 = Button(
158+
image = img3,
159+
borderwidth = 0,
160+
highlightthickness = 0,
161+
command = btn_clicked3,
162+
relief = "flat")
163+
164+
b3.place(
165+
x = 247, y = 125,
166+
width = 178,
167+
height = 34)
168+
169+
entry0_img = PhotoImage(file = f"img_textBox0.png")
170+
entry0_bg = canvas.create_image(
171+
455.0, 560.0,
172+
image = entry0_img)
173+
174+
entry0 = Text(
175+
bd = 0,
176+
bg = "#ffffff",
177+
highlightthickness = 0)
178+
179+
entry0.place(
180+
x = 250, y = 502,
181+
width = 410,
182+
height = 114)
183+
184+
entry1_img = PhotoImage(file = f"img_textBox1.png")
185+
entry1_bg = canvas.create_image(
186+
517.0, 294.5,
187+
image = entry1_img)
188+
189+
entry1 = Entry(
190+
bd = 0,
191+
bg = "#ffffff",
192+
highlightthickness = 0)
193+
194+
entry1.place(
195+
x = 377, y = 278,
196+
width = 280,
197+
height = 31)
198+
199+
entry2_img = PhotoImage(file = f"img_textBox2.png")
200+
entry2_bg = canvas.create_image(
201+
517.0, 340.5,
202+
image = entry2_img)
203+
204+
entry2 = Entry(
205+
bd = 0,
206+
bg = "#ffffff",
207+
highlightthickness = 0)
208+
209+
entry2.place(
210+
x = 377, y = 324,
211+
width = 280,
212+
height = 31)
213+
214+
entry3_img = PhotoImage(file = f"img_textBox3.png")
215+
entry3_bg = canvas.create_image(
216+
517.0, 388.5,
217+
image = entry3_img)
218+
219+
entry3 = Entry(
220+
bd = 0,
221+
bg = "#ffffff",
222+
highlightthickness = 0)
223+
224+
entry3.place(
225+
x = 377, y = 372,
226+
width = 280,
227+
height = 31)
228+
229+
entry4_img = PhotoImage(file = f"img_textBox4.png")
230+
entry4_bg = canvas.create_image(
231+
517.0, 436.5,
232+
image = entry4_img)
233+
234+
entry4 = Entry(
235+
bd = 0,
236+
bg = "#ffffff",
237+
highlightthickness = 0)
238+
239+
entry4.place(
240+
x = 377, y = 420,
241+
width = 280,
242+
height = 31)
243+
244+
window.resizable(False, False)
245+
window.mainloop()

background.png

59.7 KB
Loading

img0.png

701 Bytes
Loading

img1.png

706 Bytes
Loading

img2.png

881 Bytes
Loading

img3.png

733 Bytes
Loading

img_textBox0.png

539 Bytes
Loading

img_textBox1.png

232 Bytes
Loading

0 commit comments

Comments
 (0)