Calificación:
  • 0 voto(s) - 0 Media
  • 1
  • 2
  • 3
  • 4
  • 5
Ayuda con Programación de Inventario de Panadería hecho en Python
#1
Wink 
Hola reciban un cordial saludo me gustaría pedirles ayuda para que me den una manito con este proyecto de Inventario de una Panadería en PYTHON , tengo un pequeño lió me gustaría centrar todos los textos y que al momento de ingresar el producto le pudiera ingresar su respectiva imagen o si es posible un código de barras , pero he intentado de todo y no he podido.

CÓDIGO DE EJEMPLO
Código:
import tkinter as tk
import sqlite3
from tkinter import messagebox

######## VENTANA PARA INSETAR DATOS

def ventana_agregar():
#windows.withdraw()
window=tk.Toplevel()
window.geometry("512x512")
e1=tk.Label(window, text="AGREGAR PRODUCTOS :",bg="sky blue",fg="black").place(x=50, y=50),



# variable producto
entryproducto=tk.StringVar()
productotx=tk.Entry(window,textvariable=entryproducto).place(x=50, y=150)



# variable precio
entryprecio=tk.StringVar()
preciotx=tk.Entry(window,textvariable= entryprecio).place(x=50, y=230)



# Etiqueta para "INGRESE NOMBRE DEL PRODUCTO"
etiquetanombre=tk.Label(window, text="INGRESE NOMBRE DEL PRODUCTO.", padx=10 ).place(x=30, y=115)




#Etiqueta para "INGRESE PRECIO DEL PRODUCTO"
etiquetaprecio = tk.Label(window, text="INGRESE PRECIO DEL PRODUCTO", padx=10 ).place(x=30, y=200)

## Boton menu

menu=tk.Button(window, text="MENU", fg="red",font=("arial", 12),cursor = "hand2",relief = "raised",command = window.destroy)
menu.pack()
menu.place(x=50,y=350)

def guarda():

db = sqlite3.connect("articulos.s3db")
c = db.cursor()

nombre = entryproducto.get()
precio = entryprecio.get()


c.execute("insert into articulos (nombre,precio) values ('"+nombre+"','"+precio+"')")
db.commit()
c.close()
messagebox.showinfo("MODIFICACION","ARTICULO INGRESADO" )
window.destroy()
ventana_agregar()

btguardar = tk.Button(window, text = "GUARDAR", fg="blue",font=("arial", 12),cursor = "hand2",relief = "raised",command = guarda)
btguardar.pack()
btguardar.place(x=300,y=350)




######## VENTANA PARA VER LOS DATOS
def ventana_ver():
#.withdraw()
window=tk.Toplevel()
window.geometry("512x512")
e1=tk.Label(window, text="BUSCAR PRODUCTOS :",bg="white",fg="black").place(x=50, y=50),
e_codigo=tk.Label(window, text="CODIGO",bg="white",fg="black").place(x=50, y=70)
e_nombre=tk.Label(window, text="NOMBRE",bg="white",fg="black").place(x=150, y=70)
e_precio=tk.Label(window, text="PRECIO",bg="white",fg="black").place(x=250, y=70)
def mostrar():
## codigo
lista=tk.Listbox(window, width = 30, font=("arial", 12), height =15 )
lista.pack()
db = sqlite3.connect("articulos.s3db")
c = db.cursor()
c.execute("select * from articulos ORDER BY (codigo)DESC")
for row in c:
lista.insert(0,row[1]+"---------------"+ row[2])
lista.place(x=150,y=90)
## nombre
lista_1=tk.Listbox(window, width = 10, font=("arial", 12), height =15 )
lista_1.pack()
db = sqlite3.connect("articulos.s3db")
c = db.cursor()
c.execute("select codigo from articulos ORDER BY (codigo)DESC")
for row in c:
lista_1.insert(0,row[0])
lista_1.place(x=50,y=90)



menu=tk.Button(window, text="MENU", fg="red",font=("arial", 12),cursor = "hand2",relief = "raised",command = window.destroy)
menu.pack()
menu.place(x=50,y=400)

bt_mostrar = tk.Button(window, text = "MOSTRAR PRODUCTOS", fg="blue",font=("arial", 12),cursor = "hand2",relief = "raised",command = mostrar)
bt_mostrar.pack()
bt_mostrar.place(x=280,y=400)





########## VENTANA PARA ELIMINAR DATOS

def ventana_eliminar():
window=tk.Toplevel()
window.geometry("512x512")
e1=tk.Label(window, text=" ELIMINAR PRODUCTOS :",bg="white",fg="black").place(x=50, y=50)

#### VARIABLE PARA ID

entry_id=tk.StringVar()
productotx=tk.Entry(window,textvariable=entry_id).place(x=50, y=150)

#### ETIQUETA PARA ID

etiquetanombre=tk.Label(window, text="INGRESE CODIGO DEL PRODUCTO", padx=10 ).place(x=30, y=115)

def eliminar():
db = sqlite3.connect("articulos.s3db")
c = db.cursor()

id_producto = entry_id.get()

c.execute("DELETE from articulos where codigo = ('"+id_producto+"')")
db.commit()
c.close()
messagebox.showinfo("MODIFICACION","ARTICULO ELIMINADO" )
window.destroy()
ventana_eliminar()

#### BOTON PARA MENU

menu=tk.Button(window, text="MENU", fg="red",font=("arial", 12),cursor = "hand2",relief = "raised",command = window.destroy)
menu.pack()
menu.place(x=50,y=350)
#### BOTON PARA ELIMINAR
bt_eliminar = tk.Button(window, text = "ELIMINAR PRODUCTOS", fg="blue",font=("arial", 12),cursor = "hand2",relief = "raised",command = eliminar)
bt_eliminar.pack()
bt_eliminar.place(x=280,y=350)

###### VENTANA PARA MODIFICAR



def modificar_producto():
window=tk.Toplevel()
window.geometry("512x512")
e1=tk.Label(window, text=" MODIFICAR PRODUCTOS :",bg="white",fg="black").place(x=50, y=50)

#### VARIABLE PARA ID

entry_id=tk.StringVar()
productotx=tk.Entry(window,textvariable=entry_id).place(x=50, y=150)

#### ETIQUETA PARA ID

etiquetanombre=tk.Label(window, text="INGRESE CODIGO DEL PRODUCTO", padx=10 ).place(x=30, y=100)


#### VARIABLE PARA VALOR NUEVO

entry_valor=tk.StringVar()
valortx=tk.Entry(window,textvariable=entry_valor).place(x=50, y=250)

#### ETIQUETA PARA NUEVO VALOR

etiquetanombre=tk.Label(window, text="INGRESE EL NUEVO PRECIO PARA EL PRODUCTO", padx=10 ).place(x=30, y=200)




def modificar():
db = sqlite3.connect("articulos.s3db")
c = db.cursor()

id_producto = entry_id.get()
nuevo_precio = entry_valor.get()

c.execute("update articulos set precio =('"+nuevo_precio+"') where codigo = ('"+id_producto+"')")
db.commit()
c.close()
messagebox.showinfo("MODIFICACION","ARTICULO MODIFICADO" )
window.destroy()
modificar_producto()

#### BOTON PARA MENU

menu=tk.Button(window, text="MENU", fg="red",font=("arial", 12),cursor = "hand2",relief = "raised",command = window.destroy)
menu.pack()
menu.place(x=50,y=350)
#### BOTON PARA MODIFICAR
bt_modificar = tk.Button(window, text = "MODIFICAR PRODUCTO", fg="blue",font=("arial", 12),cursor = "hand2",relief = "raised",command = modificar)
bt_modificar.pack()
bt_modificar.place(x=280,y=350)





windows=tk.Tk()
windows.title("Panadería y pastelería “LAS DELICIAS DOÑA ANA”");
windows.geometry("800x534")

image=tk.PhotoImage(file="DOÑA ANA.gif")
image=image.subsample(1,1)
label=tk.Label(image=image)
label.place(relwidth=1, relheight=1)


b1=tk.Button(windows,text="Agregar Producto", fg="blue", font=("arial", 14), borderwidth=10,cursor = "hand2",relief = "raised", command = ventana_agregar,)
b1.pack()
b1.place(x=10,y=50)

b2=tk.Button(windows,text="Buscar Producto", fg="blue", font=("arial", 14), borderwidth=10,cursor = "hand2",relief = "raised", command = ventana_ver)
b2.pack()
b2.place(x=10,y=150)

b3=tk.Button(windows,text="Eliminar Producto", fg="blue", font=("arial", 14), borderwidth=10,cursor = "hand2",relief = "raised", command = ventana_eliminar)
b3.pack()
b3.place(x=10,y=250)

b4=tk.Button(windows,text="Modificar Producto", fg="blue", font=("arial", 14), borderwidth=10,cursor = "hand2",relief = "raised", command = modificar_producto)
b4.pack()
b4.place(x=10,y=350)
   
   
Responder
#2
Hola, bienvenido.

¿Cuál es exactamente tu problema? Por lo que veo estás mezclando dos métodos de posicionamiento de controles: pack() y place(). No deberías usar los dos simultáneamente. Te recomiendo que chequees el siguiente artículo sobre el tema: https://recursospython.com/guias-y-manua...n-tkinter/.

Saludos
¡No te pierdas nuestro curso oficial en Udemy para aprender Python, bases de datos SQL, orientación a objetos, tkinter y mucho más!

También ofrecemos consultoría profesional de desarrollo en Python para personas y empresas.
Responder
#3
Hola Gracias por la ayuda pero mas exactamente lo que estoy buscando es que lo siguiente quede centrado que aparezca centrado en la simulación del código.
Código:
b1=tk.Button(windows,text="Agregar Producto", fg="blue", font=("arial", 14), borderwidth=10,cursor = "hand2",relief = "raised", command = ventana_agregar,)
b1.pack()
b1.place(x=10,y=50)

b2=tk.Button(windows,text="Buscar Producto", fg="blue", font=("arial", 14), borderwidth=10,cursor = "hand2",relief = "raised", command = ventana_ver)
b2.pack()
b2.place(x=10,y=150)

b3=tk.Button(windows,text="Eliminar Producto", fg="blue", font=("arial", 14), borderwidth=10,cursor = "hand2",relief = "raised", command = ventana_eliminar)
b3.pack()
b3.place(x=10,y=250)

b4=tk.Button(windows,text="Modificar Producto", fg="blue", font=("arial", 14), borderwidth=10,cursor = "hand2",relief = "raised", command = modificar_producto)
b4.pack()
b4.place(x=10,y=350)
Responder
#4
Hola. Es justamente ese el problema. Te recomiendo que borres las llamadas a pack() y ajustes tu coordenada en X. Si tu ventana mide 512 píxeles de ancho, entonces para que los botones aparezcan centrados vas a tener que posicionarlos vía place() en x=250 aproximadamente.

Saludos.
¡No te pierdas nuestro curso oficial en Udemy para aprender Python, bases de datos SQL, orientación a objetos, tkinter y mucho más!

También ofrecemos consultoría profesional de desarrollo en Python para personas y empresas.
Responder
#5
Wink 
Buenos días de nuevo agradecido con tu ayuda , pero me gustaría ahora que me ayudaran con otra cosa como puedo hacer que al ingresar cada producto tambien se le pueda ingresar una imagen pues ya he intentado de todo y no logro cuadrar el código , mas exactamente algo parecido a lo que hace este java pero en python.
Gracias  Smile

Código:
$('#drag-and-drop-zone').dmUploader({
 url: '/demo/java-script/upload',
 maxFileSize: 3000000, // 3 Megs max
 allowedTypes: 'image/*',
 extFilter: ['jpg', 'jpeg','png','gif'],
 // ...
 onNewFile: function(id, file){
  //...
   if (typeof FileReader !== 'undefined'){
     var reader = new FileReader();
     var img = $('<img />');
       
     reader.onload = function (e) {
       img.attr('src', e.target.result);
     }
     /* ToDo: do something with the img! */
     reader.readAsDataURL(file);
   }
 },
 onFileTypeError: function(file){
   // ...
 },
 onFileTypeError: function(file) {
   // ...
 }
 // ...
});
Responder
#6
Hola, para examinar archivos con Tcl/Tk podés usar el módulo tkinter.filedialog. Acá tenés un ejemplo: https://www.geeksforgeeks.org/python-ask...n-tkinter/.

Saludos
¡No te pierdas nuestro curso oficial en Udemy para aprender Python, bases de datos SQL, orientación a objetos, tkinter y mucho más!

También ofrecemos consultoría profesional de desarrollo en Python para personas y empresas.
Responder
#7
(02-06-2019, 11:23 PM)Francisco escribió: Hola, para examinar archivos con Tcl/Tk podés usar el módulo tkinter.filedialog. Acá tenés un ejemplo: https://www.geeksforgeeks.org/python-ask...n-tkinter/.

Saludos

De nuevo mil gracias por su ayuda pero me gustaría que me ayudara y me dijera como es posible que guarde una imagen cuando voy a ingresar el producto me podría ayudar con el código

CÓDIGO ORIGINAL DE LA APLICACIÓN

Código:
import tkinter as tk
import sqlite3
from tkinter import messagebox

######## VENTANA PARA INSETAR DATOS    

def ventana_agregar():
   #windows.withdraw()
   window=tk.Toplevel()
   window.geometry("512x512")
   e1=tk.Label(window, text="AGREGAR PRODUCTOS :",bg="sky blue",fg="black").place(x=50, y=50),


 
# variable producto
   entryproducto=tk.StringVar()
   productotx=tk.Entry(window,textvariable=entryproducto).place(x=50, y=150)



# variable  precio
   entryprecio=tk.StringVar()
   preciotx=tk.Entry(window,textvariable=  entryprecio).place(x=50, y=230)
   

   
# Etiqueta para "INGRESE NOMBRE DEL PRODUCTO"
   etiquetanombre=tk.Label(window, text="INGRESE NOMBRE DEL PRODUCTO.", padx=10 ).place(x=30, y=115)
   
   
   

#Etiqueta para "INGRESE PRECIO DEL PRODUCTO"
   etiquetaprecio = tk.Label(window, text="INGRESE PRECIO DEL PRODUCTO", padx=10 ).place(x=30, y=200)
 
## Boton menu  

   menu=tk.Button(window, text="MENU", fg="red",font=("arial", 12),cursor = "hand2",relief = "raised",command = window.destroy)
   menu.pack()
   menu.place(x=50,y=350)
 
   def guarda():

           db = sqlite3.connect("articulos.s3db")
           c = db.cursor()

           nombre = entryproducto.get()
           precio = entryprecio.get()
         

           c.execute("insert into articulos (nombre,precio) values ('"+nombre+"','"+precio+"')")
           db.commit()
           c.close()
           messagebox.showinfo("MODIFICACION","ARTICULO INGRESADO" )
           window.destroy()
           ventana_agregar()

   btguardar = tk.Button(window, text =  "GUARDAR", fg="blue",font=("arial", 12),cursor = "hand2",relief = "raised",command = guarda)
   btguardar.pack()
   btguardar.place(x=300,y=350)

   


######## VENTANA PARA VER LOS DATOS
def ventana_ver():
   #.withdraw()
   window=tk.Toplevel()
   window.geometry("512x512")
   e1=tk.Label(window, text="BUSCAR PRODUCTOS :",bg="white",fg="black").place(x=50, y=50),
   e_codigo=tk.Label(window, text="CODIGO",bg="white",fg="black").place(x=50, y=70)
   e_nombre=tk.Label(window, text="NOMBRE",bg="white",fg="black").place(x=150, y=70)
   e_precio=tk.Label(window, text="PRECIO",bg="white",fg="black").place(x=250, y=70)
   def mostrar():
##        codigo
       lista=tk.Listbox(window, width = 30, font=("arial", 12), height =15 )
       lista.pack()
       db = sqlite3.connect("articulos.s3db")
       c = db.cursor()
       c.execute("select * from articulos ORDER BY (codigo)DESC")
       for row in c:
           lista.insert(0,row[1]+"---------------"+ row[2])
       lista.place(x=150,y=90)
##        nombre
       lista_1=tk.Listbox(window, width = 10, font=("arial", 12), height =15 )
       lista_1.pack()
       db = sqlite3.connect("articulos.s3db")
       c = db.cursor()
       c.execute("select codigo from articulos ORDER BY (codigo)DESC")
       for row in c:
           lista_1.insert(0,row[0])
       lista_1.place(x=50,y=90)

 

   menu=tk.Button(window, text="MENU", fg="red",font=("arial", 12),cursor = "hand2",relief = "raised",command = window.destroy)
   menu.pack()
   menu.place(x=50,y=400)

   bt_mostrar = tk.Button(window, text =  "MOSTRAR PRODUCTOS", fg="blue",font=("arial", 12),cursor = "hand2",relief = "raised",command = mostrar)
   bt_mostrar.pack()
   bt_mostrar.place(x=300,y=400)




   
########## VENTANA PARA ELIMINAR DATOS

def ventana_eliminar():
   window=tk.Toplevel()
   window.geometry("512x512")
   e1=tk.Label(window, text=" ELIMINAR PRODUCTOS :",bg="white",fg="black").place(x=50, y=50)
   
#### VARIABLE PARA ID
   
   entry_id=tk.StringVar()
   productotx=tk.Entry(window,textvariable=entry_id).place(x=50, y=150)

#### ETIQUETA PARA ID

   etiquetanombre=tk.Label(window, text="INGRESE CODIGO DEL PRODUCTO", padx=10 ).place(x=30, y=115)

   def eliminar():
       db = sqlite3.connect("articulos.s3db")
       c = db.cursor()

       id_producto = entry_id.get()
   
       c.execute("DELETE  from articulos where codigo = ('"+id_producto+"')")
       db.commit()
       c.close()
       messagebox.showinfo("MODIFICACION","ARTICULO ELIMINADO" )
       window.destroy()
       ventana_eliminar()
       
#### BOTON PARA MENU
   
   menu=tk.Button(window, text="MENU", fg="red",font=("arial", 12),cursor = "hand2",relief = "raised",command = window.destroy)
   menu.pack()
   menu.place(x=50,y=350)
#### BOTON PARA ELIMINAR
   bt_eliminar = tk.Button(window, text =  "ELIMINAR PRODUCTOS", fg="blue",font=("arial", 12),cursor = "hand2",relief = "raised",command = eliminar)
   bt_eliminar.pack()
   bt_eliminar.place(x=300,y=350)

###### VENTANA PARA MODIFICAR



def modificar_producto():
   window=tk.Toplevel()
   window.geometry("512x512")
   e1=tk.Label(window, text=" MODIFICAR PRODUCTOS :",bg="white",fg="black").place(x=50, y=50)
   
#### VARIABLE PARA ID
   
   entry_id=tk.StringVar()
   productotx=tk.Entry(window,textvariable=entry_id).place(x=50, y=150)

#### ETIQUETA PARA ID

   etiquetanombre=tk.Label(window, text="INGRESE CODIGO DEL PRODUCTO", padx=10 ).place(x=30, y=100)


#### VARIABLE PARA VALOR NUEVO
   
   entry_valor=tk.StringVar()
   valortx=tk.Entry(window,textvariable=entry_valor).place(x=50, y=250)

#### ETIQUETA PARA NUEVO VALOR

   etiquetanombre=tk.Label(window, text="INGRESE EL NUEVO PRECIO PARA EL PRODUCTO", padx=10 ).place(x=30, y=200)



   
   def modificar():
       db = sqlite3.connect("articulos.s3db")
       c = db.cursor()

       id_producto = entry_id.get()
       nuevo_precio = entry_valor.get()
   
       c.execute("update articulos set precio =('"+nuevo_precio+"') where codigo = ('"+id_producto+"')")
       db.commit()
       c.close()
       messagebox.showinfo("MODIFICACION","ARTICULO MODIFICADO" )
       window.destroy()
       modificar_producto()

#### BOTON PARA MENU
   
   menu=tk.Button(window, text="MENU", fg="red",font=("arial", 12),cursor = "hand2",relief = "raised",command = window.destroy)
   menu.pack()
   menu.place(x=50,y=350)
#### BOTON PARA MODIFICAR
   bt_modificar = tk.Button(window, text =  "MODIFICAR PRODUCTO", fg="blue",font=("arial", 12),cursor = "hand2",relief = "raised",command = modificar)
   bt_modificar.pack()
   bt_modificar.place(x=300,y=350)



   

windows=tk.Tk()
windows.title("Panadería y pastelería “LAS DELICIAS DOÑA ANA”");
windows.geometry("800x534")

image=tk.PhotoImage(file="DOÑA ANA.gif")
image=image.subsample(1,1)
label=tk.Label(image=image)
label.place(relwidth=1, relheight=1)

b1=tk.Button(windows,text="Panaderia y Pasteleria “LAS DELICIAS DOÑA ANA”", fg="orange", font=("arial", 16) ,borderwidth=10,cursor = "hand2",relief = "raised",)
b1.place(x=150,y=1)

b1=tk.Button(windows,text="Agregar Producto", fg="blue", font=("arial", 14) ,borderwidth=10,cursor = "hand2",relief = "raised", command = ventana_agregar,)
b1.place(x=20,y=55)

b2=tk.Button(windows,text="Buscar Producto", fg="blue", font=("arial", 14) ,borderwidth=10,cursor = "hand2",relief = "raised", command = ventana_ver)
b2.place(x=215,y=55)

b3=tk.Button(windows,text="Eliminar Producto", fg="blue", font=("arial", 14), borderwidth=10,cursor = "hand2",relief = "raised", command = ventana_eliminar)
b3.place(x=400,y=55)

b4=tk.Button(windows,text="Modificar Producto", fg="blue", font=("arial", 14) , borderwidth=10,cursor = "hand2",relief = "raised", command = modificar_producto)
b4.place(x=590,y=55)






windows.mainloop()

CÓDIGO A INGRESAR DENTRO DE LA APLICACIÓN PARA PODER GUARDAR IMAGEN JUNTO CON NOMBRE DEL PRODUCTO


  

Código:
# importing tkinter and tkinter.ttk
# and all their functions and classes
from tkinter import *
from tkinter.ttk import *
 
# importing askopenfile function
# from class filedialog
from tkinter.filedialog import askopenfile
 
root = Tk()
root.geometry('200x100')
 
# This function will be used to open
# file in read mode and only Python files
# will be opened
def save_file():
   file = askopenfile(mode ='r', filetypes =[('Image Files', '*.jpg')])
   if file is not None:
       content = file.read()
       print(content)
 
btn = Button(root, text ='Open', command = lambda:save_file())
btn.pack(side = TOP, pady = 10)
 
mainloop()
Responder
#8
Hola. Si estás usando SQLite, para guardar una imagen o cualquier otro archivo binario en un campo tenés que hacer uso del tipo de dato BLOB: https://www.sqlite.org/datatype3.html.

Saludos
¡No te pierdas nuestro curso oficial en Udemy para aprender Python, bases de datos SQL, orientación a objetos, tkinter y mucho más!

También ofrecemos consultoría profesional de desarrollo en Python para personas y empresas.
Responder


Salto de foro:


Usuarios navegando en este tema: 1 invitado(s)