jueves, 17 de octubre de 2019

Programa propio: Blockbuster.

El siguiente programa fue creado como ejemplo de una conexion entre mongoDB y Pycharm. Es un ejemplo de una terminal de renta de videojuegos de blockbuster.

Codigo:
import tkMessageBox
from Tkinter import *
from tkMessageBox import *
from Tkinter import OptionMenu
from PIL import ImageTk, Image
from pymongo import MongoClient
import datetime
global numerojuegos,cargo,total,finalconcargos,fecha
format= "%d/%m/%Y"
today = datetime.date.today()
fecha=today.strftime(format)
#Definiendo ventana
ventana = Tk()
ventana.title("Blockbuster")
ventana = Canvas(width = 420, height = 420, bg = '#3C48D1')
ventana.pack(expand = YES, fill = BOTH)
#Banner
width = 420
height = 420
img = Image.open("blockbuster.png")
img = img.resize((width,height), Image.ANTIALIAS)
photoImg = ImageTk.PhotoImage(img)
ventana.create_image(15, -150, anchor = NW, image = photoImg)
vp = Frame(ventana)
vp.pack(expand=1) #Configurar el metodo pack()
vp.config(bg="#3C48D1")
vp.config(width="300", height="400")
vp.grid(column=0, row=0, padx=(100, 100), pady=(100, 100))
vp.rowconfigure(0, weight=1)
Fecha=Label(vp,text="Fecha de Corte")
Fecha.grid(column=0, row=7)
Fecha.config(background="Yellow",foreground="black")
FechaEntry = " "
FechaEntry = Entry(vp, width=10, textvariable=FechaEntry)
FechaEntry.grid(row=8, column=0)
FechaEntry.config(background="Yellow",foreground="black")
FechaEntry.insert(0, fecha)
print fecha
tipo = StringVar(vp)
tipo.set("...")
cantidad = StringVar(vp)
cantidad.set("...")
pago = StringVar(vp)
pago.set("...")
etiqueta_tipo = Label(vp, text='Videojuego a rentar : ')
etiqueta_tipo.config(background="Yellow",foreground="black")
ent_tipo = OptionMenu(vp, tipo, "Silent Hill", "Fire Emblem Awakening", "Super Smash Bros Melee","The Witcher 3")
etiqueta_tipo.grid(row=1, column=1, padx=(10, 10), pady=(10, 10), sticky=W)
ent_tipo.grid(row=1, column=0)
ent_tipo.config(background="Yellow",foreground="black")
print ent_tipo
etiqueta_cantidad =Label(vp, text='Dias a rentar: ')
etiqueta_cantidad.config(background="Yellow",foreground="black")
ent_numero = OptionMenu(vp, cantidad, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10")
etiqueta_cantidad.grid(row=4, column=1, padx=(10, 10), pady=(10, 10), sticky=W)
ent_numero.grid(row=4, column=0)
ent_numero.config(background="Yellow",foreground="black")
etiqueta_pago =Label(vp, text='Forma de pago: ')
etiqueta_pago.config(background="Yellow",foreground="black")
ent_pago =OptionMenu(vp, pago, "Efectivo", "Tarjeta")
etiqueta_pago.grid(row=6, column=1, padx=(10, 10), pady=(10, 10), sticky=W)
ent_pago.grid(row=6, column=0)
ent_pago.config(background="Yellow",foreground="black")
def Conexion(numerojuegos,cargo,total,final):
client = MongoClient('localhost',27017)
db = client['blockbuster']
document = {'numero_juegos':numerojuegos,'pago_tarjeta':cargo,'pago_efectivo':total,'pago_finalcontarjeta':final,"Fecha_dia":fecha }
_id= db['registro'].insert(document)
def calcular():
juego = str(tipo.get())
numerojuegos = int(cantidad.get())
dinero = str(pago.get())
if juego == "Silent Hill" and numerojuegos > 0 and dinero == "Tarjeta":
total = numerojuegos * 40
cargo = total * 0.08
finalconcargos = total + cargo
tkMessageBox.showinfo("[Renta Silent Hill : Pago con Tarjeta], su total es de: " ,finalconcargos)
print numerojuegos
print cargo
print total
print finalconcargos
elif juego == "Silent Hill" and numerojuegos > 0 and dinero == "Cupon Renta 30%":
total = numerojuegos * 40
cargo = total * 0.30
finalconcargos = total - cargo
tkMessageBox.showinfo("[Silent Hill : Descuento de Cupon ], su total es de: " ,finalconcargos)
print numerojuegos
print cargo
print total
print finalconcargos
elif juego == "Silent Hill" and numerojuegos > 0 and dinero == "Efectivo":
total = numerojuegos * 40
cargo = 0
finalconcargos = 0
tkMessageBox.showinfo("[Silent Hill : Pago con Efectivo], su total es de: ", total)
print numerojuegos
print cargo
print total
print finalconcargos
elif juego == "Fire Emblem Awakening" and numerojuegos > 0 and dinero == "Tarjeta":
total = numerojuegos * 50
cargo = total * 0.08
finalconcargos = total + cargo
tkMessageBox.showinfo("[Fire Emblem Awakening : Pago con Tarjeta], su total es de: " ,finalconcargos)
print numerojuegos
print cargo
print total
print finalconcargos
elif juego == "Fire Emblem Awakening" and numerojuegos > 0 and dinero == "Efectivo":
total = numerojuegos * 50
cargo = 0
finalconcargos = 0
tkMessageBox.showinfo("[Fire Emblem Awakening : Pago con Efectivo], su total es de: " , total)
print numerojuegos
print cargo
print total
print finalconcargos
elif juego == "Super Smash Bros Melee" and numerojuegos > 0 and dinero == "Tarjeta":
total = numerojuegos * 60
cargo = total * 0.05
finalconcargos = total + cargo
tkMessageBox.showinfo("[Super Smash Bros Melee : Pago con Tarjeta], su total es de: " ,finalconcargos)
print numerojuegos
print cargo
print total
print finalconcargos
elif juego == "Super Smash Bros Melee" and numerojuegos > 0 and dinero == "Efectivo":
total = numerojuegos * 60
cargo = 0
finalconcargos = 0
tkMessageBox.showinfo("[Super Smash Bros Melee : Pago con Efectivo], su total es de: " ,total)
print numerojuegos
print cargo
print total
print finalconcargos
elif juego == "The Witcher 3" and numerojuegos > 0 and dinero == "Tarjeta":
total = numerojuegos * 100
cargo = total * 0.08
finalconcargos = total + cargo
tkMessageBox.showinfo("[The Witcher 3 : Pago con Tarjeta], su total es de: ", finalconcargos)
print numerojuegos
print cargo
print total
print finalconcargos
elif juego == "The Witcher 3" and numerojuegos > 0 and dinero == "Efectivo":
total = numerojuegos * 100
cargo = 0
finalconcargos = 0
tkMessageBox.showinfo("[The Witcher 3: Pago con Efectivo], su total es de: ", total)
print numerojuegos
print cargo
print total
print finalconcargos
Conexion(numerojuegos, cargo, total, finalconcargos)
boton = Button(vp, text='Total a Facturar', command=calcular, width=20)
boton.grid(row=8, column=1, padx=(10, 10), pady=(10, 10), sticky=N)
boton.config(background="Yellow",foreground="black")
ventana.mainloop()
view raw Blockbuster.py hosted with ❤ by GitHub
https://drive.google.com/file/d/1bD2-1oHPGTCU3_Qy15lxTEjDN6nVtWI7/view?usp=sharing