lunes, 7 de octubre de 2019

Ejemplo: Venta de boletos (MongoDB;Python).

El siguiente simula ser una terminal de venta de boletos.

Código:
from Tkinter import *
import tkMessageBox
from tkMessageBox import *
from pymongo import MongoClient
global total,boletos,area
#VENTANA CON BANNERS
ventana = Tk()
ventana.title("Venta de Boletos")
ventana = Canvas(width = 500, height = 630, bg = 'black')
ventana.pack(expand = YES, fill = BOTH)
banner1 = PhotoImage(file = 'C:\Users\Usuario\PycharmProjects\ProjectBETA/21p.gif')
ventana.create_image(10, 10, image = banner1, anchor = NW)
banner2 = PhotoImage(file = 'C:\Users\Usuario\PycharmProjects\ProjectBETA/21pb.gif')
ventana.create_image(5, 520, image = banner2, anchor = NW)
#AREA A ESCOGER
var = StringVar(ventana)
var.set("Elija un area")
etiqueta_area = Label(ventana, text='Area: ',background="yellow3",foreground="black",font=('Arial',10)).place(x=120, y=250)
ent_area = OptionMenu(ventana, var, "Pista General", "Segundo Piso", "Tercer Piso")
ent_area.config(background="yellow3",foreground="black")
ent_area.place(x=290, y=250)
#CANTIDAD DE BOELTOS
et1 = Label(ventana, text="Cantidad de boletos",background="yellow3",foreground="black",font=('Arial',10)).place(x=80, y=320)
arr1 = [1, 2, 3, 4, 5, 6, 7]
cantidad = StringVar()
s1 = Spinbox(ventana, textvariable=cantidad, values=arr1,background="yellow3",foreground="black").place(x=280, y=320)
def Conexion(total,boletos,area):
client = MongoClient('localhost', 27017)
db = client['boletos'] # me conecto con la bd empresa
document = {'Venta_boleto':total,'boletos':boletos, "Area":area}
_id = db['venta'].insert(document)
print _id
#MOSTRAR MAPA DEL EVENTO
def mostrarmapa():
mapa= Toplevel()
mapa.title("Mapa del Evento")
map = PhotoImage(file='C:\Users\Usuario\PycharmProjects\ProjectBETA/mapa.gif')
mostrar = Label(mapa, image=map)
mostrar.pack()
mapa.mainloop()
#CALCULAR TOTAL A PAGAR
def comprar():
area = str(var.get())
boletos = int(cantidad.get())
total=0
if area=="Pista General" and boletos<=4:
total=boletos*1900
print total
print boletos
print area
tkMessageBox.showinfo("Total", cantidad.get()+" boletos para Pista General, su total es de: " + str(total))
elif area=="Pista General" and boletos>4:
showerror("Error", "No se permite adquirir mas de 4 boletos para esta area")
elif area=="Segundo Piso" and boletos>0:
total = boletos * 1500
print total
print boletos
print area
tkMessageBox.showinfo("Total", cantidad.get()+" boletos para Segundo Piso, su total es de: " + str(total))
elif area=="Tercer Piso" and boletos>0:
total = boletos * 1200
print total
print boletos
print area
tkMessageBox.showinfo("Total", cantidad.get()+" boletos para Tercer Piso, su total es de: " + str(total))
Conexion(total,boletos, area)
#BOTONES
b1=Button(ventana, text='Mostrar mapa',background="yellow3",foreground="black", command=mostrarmapa,font=('Arial',10)).place(x=170, y=400)
b2=Button(ventana, text='Pagar', background="yellow3",foreground="black", command=comprar,font=('Arial',10)).place(x=275, y=400)
ventana.mainloop()
view raw boletos.py hosted with ❤ by GitHub