120 lines
3.7 KiB
Python
Executable File
120 lines
3.7 KiB
Python
Executable File
"""
|
|
Implementación básica librería TKinter
|
|
"""
|
|
from tkinter import *
|
|
from tkinter import messagebox
|
|
from db import Database
|
|
|
|
db = Database('store.db')
|
|
|
|
def poblar_lista():
|
|
parts_list.delete(0, END)
|
|
for row in db.fetch():
|
|
parts_list.insert(END, row)
|
|
|
|
def add_item():
|
|
if part_text.get()=='' or cliente_text.get()=='' or proveedor_text.get()=='' or precio_text.get()=='':
|
|
messagebox.showerror('Campos requeridos', 'Favor completa todos los campos')
|
|
return
|
|
db.insert(part_text.get(), cliente_text.get(), proveedor_text.get(), precio_text.get())
|
|
parts_list.delete(0, END)
|
|
parts_list.insert(END, (part_text.get(), cliente_text.get(), proveedor_text.get(), precio_text.get()))
|
|
limpiar_texto()
|
|
poblar_lista()
|
|
|
|
def select_item(event):
|
|
try:
|
|
global selected_item
|
|
index = parts_list.curselection()[0]
|
|
selected_item = parts_list.get(index)
|
|
|
|
part_entry.delete(0, END)
|
|
part_entry.insert(END, selected_item[1])
|
|
cliente_entry.delete(0, END)
|
|
cliente_entry.insert(END, selected_item[2])
|
|
proveedor_entry.delete(0, END)
|
|
proveedor_entry.insert(END, selected_item[3])
|
|
precio_entry.delete(0, END)
|
|
precio_entry.insert(END, selected_item[4])
|
|
except IndexError:
|
|
pass
|
|
|
|
def remove_item():
|
|
db.remove(selected_item[0])
|
|
limpiar_texto()
|
|
poblar_lista()
|
|
|
|
def update_item():
|
|
db.update(selected_item[0],part_text.get(), cliente_text.get(), proveedor_text.get(), precio_text.get())
|
|
poblar_lista()
|
|
|
|
def limpiar_texto():
|
|
part_entry.delete(0, END)
|
|
cliente_entry.delete(0, END)
|
|
proveedor_entry.delete(0, END)
|
|
precio_entry.delete(0, END)
|
|
|
|
#Crear objeto ventana
|
|
app = Tk()
|
|
app.title('Administrador de Partes')
|
|
app.geometry('850x350')
|
|
|
|
#Parte
|
|
part_text = StringVar()
|
|
part_label = Label(app,text='Nombre de Parte', font=('bold', 14), pady=20)
|
|
part_label.grid(row=0, column=0, sticky=W)
|
|
part_entry = Entry(app, textvariable=part_text, font=(14))
|
|
part_entry.grid(row=0, column=1)
|
|
|
|
#Cliente
|
|
cliente_text = StringVar()
|
|
cliente_label = Label(app,text='Cliente', font=('bold', 14))
|
|
cliente_label.grid(row=0, column=2, sticky=W)
|
|
cliente_entry = Entry(app, textvariable=cliente_text, font=(14))
|
|
cliente_entry.grid(row=0, column=3)
|
|
|
|
#Proveedor
|
|
proveedor_text = StringVar()
|
|
proveedor_label = Label(app,text='Proveedor', font=('bold', 14))
|
|
proveedor_label.grid(row=1, column=0, sticky=W)
|
|
proveedor_entry = Entry(app, textvariable=proveedor_text, font=(14))
|
|
proveedor_entry.grid(row=1, column=1)
|
|
|
|
#Precio
|
|
precio_text = StringVar()
|
|
precio_label = Label(app,text='Precio', font=('bold', 14))
|
|
precio_label.grid(row=1, column=2, sticky=W)
|
|
precio_entry = Entry(app, textvariable=precio_text, font=(14))
|
|
precio_entry.grid(row=1, column=3)
|
|
|
|
#Lista de Partes
|
|
parts_list = Listbox(app, height=10, width=100)
|
|
parts_list.grid(row=3, column=0, columnspan=3, rowspan=6, pady=20, padx=20)
|
|
|
|
#ScrollBar
|
|
scrollbar = Scrollbar(app)
|
|
scrollbar.grid(row=3, column=3)
|
|
#Link Scrollbar a ListBox
|
|
parts_list.configure(yscrollcommand=scrollbar.set)
|
|
scrollbar.configure(command=parts_list.yview)
|
|
#Bindear Select
|
|
parts_list.bind('<<ListboxSelect>>', select_item)
|
|
|
|
#Botones
|
|
add_btn = Button(app, text='Agregar Pieza', width=12, command=add_item)
|
|
add_btn.grid(row=2, column=0, pady=20)
|
|
|
|
remove_btn = Button(app, text='Borrar Pieza', width=12, command=remove_item)
|
|
remove_btn.grid(row=2, column=1)
|
|
|
|
update_btn = Button(app, text='Actualizar', width=12, command=update_item)
|
|
update_btn.grid(row=2, column=2)
|
|
|
|
limpiar_btn = Button(app, text='Limpiar', width=12, command=limpiar_texto)
|
|
limpiar_btn.grid(row=2, column=3)
|
|
|
|
poblar_lista()
|
|
#Iniciar Programa
|
|
app.mainloop()
|
|
|