CONEXION MONGODB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
from Tkinter import * | |
import Tkinter as tk | |
import tkMessageBox | |
global cad, TH, CH, PR, CR, PP, CP, PB, CB, totf, iva, totalP, FP | |
from pymongo import MongoClient | |
def thamb(): | |
hamb = var1.get() | |
cantidad = cant.get() | |
costohamb = 0 | |
if hamb == "Hamburguesa sencilla": | |
costohamb = 15 | |
elif hamb == "Hamburguesa Doble": | |
costohamb = 25 | |
elif hamb == "Hamburguesa triple": | |
costohamb = 35 | |
costo = cantidad * costohamb | |
return costo | |
def comp(): | |
costocomp = 0 | |
cantidadR = cant1.get() | |
cantidadP = cant2.get() | |
cantidadB = cant3.get() | |
refresco = CheckVar1.get() | |
papas = CheckVar2.get() | |
burrito = CheckVar3.get() | |
if refresco == 1: | |
costocomp = costocomp + (15 * cantidadR) | |
if papas == 1: | |
costocomp = costocomp + (20 * cantidadP) | |
if burrito == 1: | |
costocomp = costocomp + (18 * cantidadB) | |
return costocomp | |
def impuesto(): | |
imp = (0.15 * (thamb() + comp())) | |
return imp | |
def limpiarcajas(): | |
cuadrohamb.delete(0, 'end') | |
cuadrorefresco.delete(0, 'end') | |
cuadroburrito.delete(0, 'end') | |
cuadropapas.delete(0, 'end') | |
limpiarbotones() | |
def limpiarbotones(): | |
var1.set("No ha selecionado") | |
CheckVar1.set(None) | |
CheckVar2.set(None) | |
CheckVar3.set(None) | |
var.set(None) | |
rtotalfinal = Label(miFrame, text=" ", bg="yellow", font=("Arial", 14), ).grid(row=9, column=2, pady="1", | |
padx="15", sticky="w") | |
riva = Label(miFrame, text=" ", bg="yellow", font=("Arial", 14)).grid(row=8, column=2, pady="1", | |
padx="15", sticky="w") | |
rtotal = Label(miFrame, text=" ", bg="yellow", font=("Arial", 14)).grid(row=7, column=2, pady="1", | |
padx="15", sticky="w") | |
limpiarlistapedido() | |
def listapedido(): | |
cad = "" | |
hamb = var1.get() | |
refresco = CheckVar1.get() | |
papas = CheckVar2.get() | |
burrito = CheckVar3.get() | |
listpedido = Listbox(miFrame, width=50) | |
if hamb != "No ha selecionado" or refresco == 1 or papas == 1 or burrito == 1: | |
if hamb == "Hamburguesa sencilla": | |
cad += "Hamburguesa sencilla $15 c/u" | |
elif hamb == "Hamburguesa Doble": | |
cad += "Hamburguesa Doble $25 c/u" | |
elif hamb == "Hamburguesa triple": | |
cad += "Hamburguesa triple $35 c/u" | |
listpedido.insert(0, cad) | |
# insert | |
if refresco == 1: | |
listpedido.insert(1, "Refresco $15 c/u") | |
if papas == 1: | |
listpedido.insert(2, "Papas $20 c/u") | |
if burrito == 1: | |
listpedido.insert(3, "Burrito $18 c/u") | |
# DELETE | |
elif hamb == "No ha selecionado" and refresco == 0 and papas == 0 and burrito == 0: | |
listpedido.delete(0) | |
listpedido.delete(1) | |
listpedido.delete(2) | |
listpedido.delete(3) | |
listpedido.grid(row=2, column=2, pady="1", padx="4") | |
def limpiarlistapedido(): | |
CheckVar1.set(0) | |
CheckVar2.set(0) | |
CheckVar3.set(0) | |
listapedido() | |
def totali(): | |
total = thamb() + comp() | |
return total | |
def totalf(): | |
TH = var1.get() | |
CH = cant.get() | |
PR = CheckVar1.get() | |
CR = cant1.get() | |
PP = CheckVar2.get() | |
CP = cant2.get() | |
PB = CheckVar3.get() | |
CB = cant3.get() | |
formapago = var.get() | |
totf = 0 | |
if TH != "No ha selecionado" or PR == 1 or PP == 1 or PB == 1: | |
if TH == "Hamburguesa sencilla": | |
print "Hamburguesa sencilla, cantidad: ", CH | |
elif TH == "Hamburguesa Doble": | |
print "Hamburguesa Doble, cantidad: ", CH | |
elif TH == "Hamburguesa triple": | |
print "Hamburguesa triple, cantidad: ", CH | |
if PR == 1: | |
print "Refresco, cantidad: ", CR | |
if PP == 1: | |
print "Papas, cantidad: ", CP | |
if PB == 1: | |
print "Burrito, cantidad: ", CB | |
if formapago == 1: | |
totf = totali() + impuesto() | |
iva = impuesto() | |
FP = "Tarjeta" | |
print "Forma de pago: ", FP | |
elif formapago == 2: | |
totf = totali() | |
iva = 0 | |
FP = "Efectivo" | |
print "Forma de pago: ", FP | |
totalP = totali() | |
print "Total: ", totalP | |
print "Iva: ", iva | |
print "Total final: ", totf | |
rtotalfinal = Label(miFrame, text=totf, bg="yellow", font=("Arial", 14), ).grid(row=9, column=2, pady="1", | |
padx="15", sticky="w") | |
riva = Label(miFrame, text=iva, bg="yellow", font=("Arial", 14)).grid(row=8, column=2, pady="1", padx="15", | |
sticky="w") | |
rtotal = Label(miFrame, text=totali(), bg="yellow", font=("Arial", 14)).grid(row=7, column=2, pady="1", padx="15", | |
sticky="w") | |
listapedido() | |
conexion(TH, CH, CB, CR, CP, formapago, totf) | |
def conexion(TH, CH, CB, CR, CP, formapago, totf): | |
print 'envio a base de datos' | |
client = MongoClient('localhost', 27017) | |
db = client['PuntoVenta'] | |
document = {'tipo_de_hamburguesa': TH, 'cantidad_hamburguesa': CH, 'cantidad_burritos': CB, | |
'cantidad_refrescos': CR, 'cantidad_papas': CP, 'tipo_pago': formapago, 'total_con_iva': totf} | |
_id = db['Ventas'].insert(document) | |
print _id | |
return | |
def ocultar(ventana): ventana.withdraw() | |
raiz = Tk() | |
raiz.title("ventana primaria") | |
raiz.resizable(1, 1) # para permitir agrandar o no el ancho o la altura con el moyuse | |
# raiz.geometry("500x600") | |
raiz.config(bg="orange") | |
raiz.config(bd=15) | |
raiz.config(relief="groove") | |
miFrame = Frame(raiz) | |
miFrame.pack() | |
miFrame.config(bg="yellow") | |
miFrame.config(bd=10) | |
miFrame.config(relief="sunken") | |
miFrame.config(cursor="hand2") | |
# Etiquetas | |
miLabel1 = Label(miFrame, text="Hamburguesa feliz", fg="red", bg="yellow", font=("Arial Black", 25)).grid(row=0, | |
column=0, | |
pady="4") | |
OrdenH = Label(miFrame, text="Seleccione la hamburguesa", bg="yellow", font=("Arial", 14)).grid(row=1, column=0, | |
pady="1", padx="15", | |
sticky="w") | |
Pedido = Label(miFrame, text="Pedido:", bg="yellow", font=("Arial", 14)).grid(row=1, column=2, pady="1") | |
cantidadhamb = Label(miFrame, text="Cantidad de Hamburguesas:", bg="yellow", font=("Arial", 14)).grid(row=2, column=0, | |
pady="1", | |
padx="15", | |
sticky="w") | |
complementos = Label(miFrame, text="Complementos:", bg="yellow", font=("Arial", 14)).grid(row=3, column=0, pady="1", | |
padx="15", sticky="w") | |
Cantidadcomp = Label(miFrame, text="Cantidad complementos:", bg="yellow", font=("Arial", 14)).grid(row=3, column=1, | |
pady="1", padx="15", | |
sticky="w") | |
Formadepago = Label(miFrame, text="Forma de pago:", bg="yellow", font=("Arial", 14)).grid(row=7, column=0, pady="1", | |
padx="15", sticky="w") | |
Total = Label(miFrame, text="Total:", bg="yellow", font=("Arial", 14)).grid(row=7, column=1, pady="1", padx="15", | |
sticky="w") | |
IVA = Label(miFrame, text="IVA:", bg="yellow", font=("Arial", 14)).grid(row=8, column=1, pady="1", padx="15", | |
sticky="w") | |
TotalFinal = Label(miFrame, text="Total final:", bg="yellow", font=("Arial", 14)).grid(row=9, column=1, pady="1", | |
padx="15", sticky="w") | |
# OptionMenu | |
var1 = tk.StringVar(miFrame) | |
var1.set("No ha selecionado") | |
opciones = ["Hamburguesa sencilla", "Hamburguesa Doble", "Hamburguesa triple"] | |
opcion = tk.OptionMenu(miFrame, var1, *opciones) | |
opcion.config(width=20) | |
opcion.grid(row=1, column=1) | |
# ListBox | |
c = Listbox(miFrame, width=50).grid(row=2, column=2, pady="1", padx="4") | |
# Entrys | |
cant = tk.IntVar(miFrame) | |
cant1 = tk.IntVar(miFrame) | |
cant2 = tk.IntVar(miFrame) | |
cant3 = tk.IntVar(miFrame) | |
cuadrohamb = Entry(miFrame, textvariable=cant) | |
cuadrohamb.grid(row=2, column=1, pady="1") | |
cuadrohamb.config(fg="blue", justify="center") | |
cuadrorefresco = Entry(miFrame, textvariable=cant1) | |
cuadrorefresco.grid(row=4, column=1, pady="1") | |
cuadrorefresco.config(fg="blue", justify="center") | |
cuadropapas = Entry(miFrame, textvariable=cant2) | |
cuadropapas.grid(row=5, column=1, pady="1") | |
cuadropapas.config(fg="blue", justify="center") | |
cuadroburrito = Entry(miFrame, textvariable=cant3) | |
cuadroburrito.grid(row=6, column=1, pady="1") | |
cuadroburrito.config(fg="blue", justify="center") | |
# Checkbutton | |
CheckVar1 = IntVar() # | |
CheckVar2 = IntVar() | |
CheckVar3 = IntVar() | |
Refresco = Checkbutton(miFrame, text="Refresco", bg="yellow", variable=CheckVar1) | |
Refresco.grid(row=4, column=0, sticky="w", padx="15") | |
Refresco.config(onvalue=1, offvalue=0) | |
Papas = Checkbutton(miFrame, text="Papas", bg="yellow", variable=CheckVar2) | |
Papas.grid(row=5, column=0, sticky="w", padx="15") | |
Papas.config(onvalue=1, offvalue=0) | |
Burrito = Checkbutton(miFrame, text="Burrito", bg="yellow", variable=CheckVar3) | |
Burrito.grid(row=6, column=0, sticky="w", padx="15") | |
Burrito.config(onvalue=1, offvalue=0) | |
# Radiobutton | |
var = IntVar() | |
R1 = Radiobutton(miFrame, text="Tarjeta de credito", bg="yellow", variable=var, value=1) # , command=sel) | |
R1.grid(row=8, column=0, sticky="w", padx="15") | |
R2 = Radiobutton(miFrame, text="Efectivo", bg="yellow", variable=var, value=2) # , command=sel) | |
R2.grid(row=9, column=0, sticky="w", padx="15") | |
# botones | |
Cancelar = Button(miFrame, text="Cancelar", command=limpiarcajas) | |
Cancelar.grid(row=10, column=0, sticky="w", padx="15") | |
Comprar = Button(miFrame, text="Hacer pedido", bg="Green", command=totalf) | |
Comprar.grid(row=10, column=2, sticky="e", padx="15") | |
Terminar = Button(raiz, text="Terminar", bg="Red", command=lambda: ocultar(raiz)) | |
Terminar.pack() | |
raiz.mainloop() |
Comentarios
Publicar un comentario