lunes, 11 de noviembre de 2019

Conexion Mango db.

autores: Cynthia Lizeth Barron Morales, Alfredo De Jesus Santos Gutierrez

#!/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.iconbitmap("Hamburger.ico")
#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()

Interfaz con el boton cancelar explicacion.

# -*- coding: utf-8 -*-
from Tkinter import *
import Tkinter as tk
import tkMessageBox
global cad

"""Creamos una funcion para saber el tipo de hamburguesa seleccionado y la cantidad de pedido,
utilizamos el get para obtener los datos almacenados en las variables pertenecientes del frame,
en esta funcion utilizamos condiciones if, y elif, ya que si no es una es otra, en cada  condicion
se le es añadido a una variable el costo de la hamburguesa, esta variable es declarada inicialmente en 0,
despues de salir de las condiciones nos muestra una variable la cual su valor sera igual a la multiplicacion
de cantidad por el costo de la hamburguesa, esto seria el equivalente al costo total de las hamburguesas el cual vamos a
 retornar para utilizar a futuru."""
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

""" Creamos al igual una funcion la cual contendra la selecion de complementos y la cantidad de ellos introducidas,
utilizamos el get para obtener los datos almacenados en las variables pertenecientes del frame,
declaramos una variable para el costo total de los complementos, la cual la inicializamos en 0,
en esta funcion utilizamos condiciones if, ya que vamos a evaluar las tres, ya que esta conectado a un
checkbutton puede haber mas de una opcion o ninguna, dentro de los if utilizamos la variable del costo total de
complemetos la cual tendra el calor de si misma mas la multiplicacion del precio por la cantidad del complemento,
esto se almacena en la variable y al final de los if, la retornamos para posteriormente utilizarla."""
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

"""Creamos una funcion para calcular el impuesto, este impuesto se manejara cuando el pago se con tarjeta, usamos una variable llamada iva que sera igual
a la multiplicacion del 15% por el total el cual se realiza en totali, despues retornamos el iva para usarlo despues.
"""
def impuesto():
    iva = 0.15 * totali()
    return iva

"""En la interfaz nos dice total, es decir que con esta funcion sumaremos el total de la hamburguesa  mas el total de los complementos,
y retornamos el resultado de la suma para usarla para calcular el impuesto y el total final
"""
def totali():
    total=thamb()+comp()
    return total

"""La funcion creada a continuacion es para calcular el total final, el cual dependera de la forma de pago, ya que si es con tarjeta se aplica un impuesto, y si no el precio es el mismo que el totali,
para esto obtenemos con el get el valor de la variable que almacena la opcion del radio botton, y declaramos una variable para guardar el total final, la cual inicializaremos en 0,
en este caso utilizaremos el if y elif, ya que si no es una debe ser la otra, y si no con un else mandamos una tkMessengebox diciendo que no se ha seleccionado la forma de pago,
en el if de pago con tarjeta, cuando esta se cumple, la variable total final sera igual a la suma de las funciones totali mas impuesto, y declararemos una variable llamada iva en la cual sera igual a la funcion impuesto,
si el pago es con efectivo en elif tomaremos la variable total final igualandola a la funcion totali, y declarando la variable iva igual a 0, esto con el fin de que podamos imprimir en una etiqueta el calor del totali,
total final y del iva como se muestran los Label despues de las condiciones, en esta funcion hacemos llamar la funcion listapedido la cual creara una lista de los productos seleccionados"""
def totalf():
    formapago=var.get()
    totf=0
    if formapago ==1:
        totf=totali()+impuesto()
        iva=impuesto()

    elif formapago ==2:
        totf=totali()
        iva=0
    else:
        tkMessageBox.showerror("Error "," no se ha seleccionado una forma de pago")
    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()


"""Creamos esta funcion para insertar los productos selecionados en un Listbox, para insertar y elimiar, esto se debe hacer despues de declarar el listbox pero antes de empaquetarlo, o de poner ya sea .grid,.config,.pack
 para insertar creamos un if para ver si hay algun producto seleccionado, si hay entra y compara, para el caso de la seleccion de la hamburguesas declaramos una variable global en la vamos a usar para las tres condiciones
 de las hamburguesas, despues de salir de las condiciones tenemos la sintasix para insertar que es nombrelistbox.insert(numerodeposicion,"texto a insertar, o en el caso de las hamburguesas la variable),
 para poder eliminar usamos la siguiente sintaxis: nombrelistbox.delete(numerodeposicionaborrar), despues de poner lo insert o los delete, empaquetamos el listbox y listo """
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")

"""para Limpiar las cajas, tenemos la opcion de borar desde un inicio fijado hasta el final del texto disponible en el entry,
 gracias a un indice que nos da TKinter que es 'END', con este podemos de la siguiente
forma borrar desde el inicio hasta el final sin necesitar conocer cuantos caracteres componen el texto contenido en el widget,
este empieza una cadenita de llamado de funciones para limpiar la interfaz
cuando oprimimos cancelar"""
def limpiarcajas():
    cuadrohamb.delete(0, 'end')
    cuadrorefresco.delete(0,'end')
    cuadroburrito.delete(0,'end')
    cuadropapas.delete(0,'end')
    limpiarbotones()

"""para limpiar los botones simplemente mandamos con el set en el de el menu el mensaje inicial, y en los otros mandamos None,
 pero esto se lo asignamos a las varibles usadas para los botones.
Para limpiar las etiquetas de los totales y el impuesto imprimimos una etiqueta en blanco
"""
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()

"""Para limpiar la lista pedido o Listbox las variables de los checkbutton y las cajas de los complementos les mandamos con el set el valor de 0,
asi llamando a la funcion listapedido se ira a la parte del delete y por ultimo mostramos un mensaje de que se ha borrado todo y puede volver a pedir
"""
def limpiarlistapedido():
    cant.set(0)
    cant1.set(0)
    cant2.set(0)
    cant3.set(0)
    CheckVar1.set(0)
    CheckVar2.set(0)
    CheckVar3.set(0)
    listapedido()
    tkMessageBox.showinfo("Cancelacion exitosa", "Se ha cancelado el pedido, y esta listo para realizar nuevo pedido")

"""Para terminar el programa utilizamos esta funcion de ocultar,
 aunque otra opcion podria ser destroy
 """
def ocultar(ventana): ventana.withdraw()

#Creacion de la ventana principal
"""Como ya hemos visto las creaciones de ventana, hic
raiz.title("ventana primaria")imos una ventana raiz, en la cual creamos un frame,
con el relief(atributo que se le da a configuracion) caqmbiamos el diseño de la ventanas, con el bd el tamaño del borde y con el cursor el tipo de cursor
"""
raiz=Tk()
raiz.resizable(1,1) #para permitir agrandar o no el ancho o la altura con el moyuse
#raiz.iconbitmap("Hamburger.ico")
#raiz.geometry("500x600")
raiz.config(bg="orange")
raiz.config(bd=15)
raiz.config(relief="groove")
"""Al crear el Frame debemos indicar a quien pertenece en este caso el frame pertenece a la raiz, todos los componentes creados para la interfaz van a pertenecer al frame,
aunque tambien pueden pertenecer a la raiz, en este caso solo un boton pertenecera a la raiz."""
miFrame=Frame(raiz)
miFrame.pack()
miFrame.config(bg="yellow")
miFrame.config(bd=10)
miFrame.config(relief="sunken")
miFrame.config(cursor="hand2")

#Etiquetas

"""Nombre de la etiqueta = Label (a quien pertenece, text(indica que es lo que mostrara)=El texto a mostrar,
 fg(color de letra)=color en ingles o puede ser en hexadecimal,
bg(lo utilizamos para indicar el color del fondo este lo indicamos para cuando usamos un color diferente al predeterminado)=color del fondo,
font(aqui podemos indicar el tipo de letra y el tamaño del texto)=("tipoletra",Tamaño en #)).grid(utilizamos el .grid para darle la posicion
en el frame es decir crea una cuadicula que podriamos decir que es como una matriz)(row=numerodefila,column=numerodecolumna,
pady="numerode separacionenY",sticky="Posicion se indica con los puntos cardenales en ingles
N, S, E, W se utiliza solo la inicial ")"""

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")

#Lista de opciones desplegable

"""para la menu de opciones o mejor conocidas como OptionMenu, creamos una variable la cual declaramos de tipo string e indicamos a donde pertenecees decir:

nombredelavariable=tk.StringVar(aquienpertenece)                           .esta variable la usaremos para guardar la opcion seleccionada, pero como al inicio
                                                                           no tiene ninguna seleccionada ponemos:
nombredelavariable.set("Mensaje")                                          el set es para enviar, creamos un arreglo con las opciones es decir:
nombrearreglo=["Op1","Op2",...,"Opn"]                                      , enseguida de crear el arreglo creamos el OptionMenu la sintaxis seria:
nombre=tk.OptionMenu(aquienpertenece,nombredelavariable,*nombrearreglo)    ya que usaremos config para el ancho y grid para la pocicion tengremos que escribir separados, es decir:
nombre.config(width=anchoennumero)
nombre.grid(row=numerofila,column=numerocolumna)                           esto seria para crear un menu de opciones"""

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

"""para crear un listbox la sintaxis seria:
nombre=Listbox(aquienpertenece, width=anchonumero)
nombre.grid(row=numerofila, column=numerocolumna, pady="numerodeespacioenY", padx="numerodeespacioenX"), esto seria para crear el puro cascaron,
para ingresar datos lo vemos en la funcion listapedido(), el de la linea 202 es por simple estetica"""

c= Listbox(miFrame, width=50).grid(row=2, column=2, pady="1", padx="4")

#Entrys

"""Los entrys son cajas de texto, como todos conocemos sirven para ingresar, pero tambien podemos imprimir en ellos
como cada caja de texto o entry es individual debemos crear una variable para cada una a usar y la declararemos de que tipo de dato hablamos.

nombrevariablecaja=tk.IntVar'tipo de dato'(aquienpertenece)                          esto solo es la variable donde almacenaremos el dato ingresado en el entry la siguiente sintaxis
                                                                                     es para crear el entry:
nombreentry=Entry(aquienpertenece, textvariable=nombrevariablecaja)                  el textvariable es para indicar donde almacenaremos lo que ingresamos en el entry
nombreentry.grid(row=numerofila,column=numerocolumna,pady="numerodeespacionenY")     igual que todos los elementos utilizamos el grid para indicar su pocicion,
                                                                                     y si queremos un interlineado por llamarlo de una forma
nombreentry.config(fg="colordetexto", justify="posicion de justificacion")           en el config utilizanmos el justify, este utiliza para justificar el texto como 
                                                                                     si usaramos word solo indicamos center, left o right"""

cant=tk.IntVar(miFrame)
cant.set(0)
cant1=tk.IntVar(miFrame)
cant1.set(0)
cant2=tk.IntVar(miFrame)
cant2.set(0)
cant3=tk.IntVar(miFrame)
cant3.set(0)
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
"""El Checkbutton es una casilla de verificación que al igual que los entry son individuales, es decir que son  lo contrario a los radiobutton, el checkbutton nos permite elegir mas de 1 opcion
al mismo tiempo para estro declararemos una variable para cada checkbutton:
nombrevariableCheckButton=tipodedato()                                                   para crear el checkbutton:
nombreCheckbutton=Checkbutton(aquienpertenece,text="Texto a verificar",bg="color fondo", variable=nombrevariableCheckButton)       
nombreCheckbutto.grid(row=numerofila,column=numerocolumna, sticky="posicion",padx="separacionenX")
nombreCheckbutto.config(onvalue=1, offvalue=0)                                           para dar el valor 1 cuando lo seleccionamos y de 0 cuando no """

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
"""El radio button es un boton de seleccion compartida es decir que si seleccionamos una no podemos seleccionar la otra,
un ejemplo de esto seria la opcion de sexo ya sea mujer u hombre
es decir que comparte la misma variable la sintaxis es:

nombrevariable= IntVar()
nombreRadiobutton1 = Radiobutton(aquienpertenece, text="texto opcion1", bg="color fondo", variable=nombrevariable, value=1)      value es el valor que tomara la variable, este servira para saber cual opcion se selecciono y trabajar con ella
nombreRadiobutton1.grid(row=numerofila,column=numerocolumna, sticky="posicion",padx="separacionenX")                           
nombreRadiobutton2 = Radiobutton(aquienpertenece, text="texto opcion2", bg="color fondo", variable=nombrevariable, value=2)
nombreRadiobutton2.grid(row=numerofila,column=numerocolumna, sticky="posicion",padx="separacionenX")  """
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
"""Los botones hacen un evento en este caso llaman a uno o mejor dijo llaman a una funcion. La sintaxis seria la siguiente:
nombreboton=Button(aquienpertenece, text= "texto que mostrara el boton",command=llamandolafuncion)     
nombreboton.grid(row=numerofila,column=numerocolumna, sticky="posicion",padx="separacionenX")                                          """
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()

Interfaz con boton de cancelar.

# -*- coding: utf-8 -*-
from Tkinter import *
import Tkinter as tk
import tkMessageBox
global cad

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():
    iva = (0.15 * (thamb() + comp()))
    return iva

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():
    cant.set(0)
    cant1.set(0)
    cant2.set(0)
    cant3.set(0)
    CheckVar1.set(0)
    CheckVar2.set(0)
    CheckVar3.set(0)
    listapedido()
    tkMessageBox.showinfo("Cancelacion exitosa", "Se ha cancelado el pedido, y esta listo para realizar nuevo pedido")

def totali():
    total=thamb()+comp()
    return total

def totalf():
    formapago=var.get()
    totf=0
    if formapago ==1:
        totf=totali()+impuesto()
        iva=impuesto()

    elif formapago ==2:
        totf=totali()
        iva=0
    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()

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.iconbitmap("Hamburger.ico")
#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")



#Lista de opciones desplegable
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)

c= Listbox(miFrame, width=50).grid(row=2, column=2, pady="1", padx="4")



#Entrys
cant=tk.IntVar(miFrame)
cant.set(0)
cant1=tk.IntVar(miFrame)
cant1.set(0)
cant2=tk.IntVar(miFrame)
cant2.set(0)
cant3=tk.IntVar(miFrame)
cant3.set(0)
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()

Interfaz con listbox.

# -*- coding: utf-8 -*-
from Tkinter import *
import Tkinter as tk
import tkMessageBox
global cad

def thamb():
    hamb=var1.get()
    cantidad=cant.get()
    if hamb == "Hamburguesa sencilla":
        costohamb=15
    elif hamb == "Hamburguesa Doble":
        costohamb=25
    else:
        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():
    iva = (0.15 * (thamb() + comp()))
    return iva

def listapedido():
    cad=""
    hamb = var1.get()
    refresco = CheckVar1.get()
    papas = CheckVar2.get()
    burrito = CheckVar3.get()
    listpedido = Listbox(miFrame, width=50)
    if hamb == "Hamburguesa sencilla":
        cad +="Hamburguesa sencilla $15 c/u"
    elif hamb == "Hamburguesa Doble":
        cad += "Hamburguesa Doble $25 c/u"
    else:
        cad += "Hamburguesa triple $35 c/u"
    listpedido.insert(0, cad)
    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")
    listpedido.grid(row=2, column=2, pady="1", padx="4")



def totali():
    total=thamb()+comp()
    return total

def totalf():
    formapago=var.get()
    totf=0
    if formapago ==1:
        totf=totali()+impuesto()
        iva=impuesto()

    elif formapago ==2:
        totf=totali()
        iva=0
    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()

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.iconbitmap("Hamburger.ico")
#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")



#Lista de opciones despegable
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)

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=totalf)
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()

Comprobacion con uso de clases.



usuarioc

class usuario_validar():
    errors = []

    def longitud(self, usercomp):
        if len(usercomp) < 6:
            self.errors.append('El nombre de usuario debe contener al menos 6 caracteres')
            return False

        elif len(usercomp) > 12:
            self.errors.append('El nombre de usuario debe contener maximo 12 caracteres')
            return False

        else:
            return True

    def alfanumerico(self, usercomp):
        if usercomp.isalnum() == False:
            self.errors.append('El nombre de usuario puede contener solo letras y numeros')
            return False
        else:
            return True

    def validar_usuario(self, usercomp):
        valido = self.longitud(usercomp) and self.alfanumerico(usercomp)
        return valido



paswordc


class password_validar():

    errors=[]

    def longitud(self, passw):
        if len(passw) < 8:
            self.errors.append('La contrasena debe tener al menos 8 caracteres')
            return False
        else:
            return True

    def minuscula(self, passw):
        letras_minuscula=False
        for carac in passw:
            if carac.islower()==True:
                letras_minuscula=True
        if not letras_minuscula:
            self.errors.append('La contrasena debe tener al menos una minuscula')
            return False
        else:
            return True

    def mayuscula(self, passw):
        letras_mayuscula=False
        for carac in passw:
            if carac.isupper()==True:
                letras_mayuscula=True
        if not letras_mayuscula:
            self.errors.append('La contrasena debe tener al menos una mayuscula')
            return False
        else:
            return True

    def numero(self, passw):
        num=False
        for carac in passw:
            if carac.isdigit()== True:
                num=True

        if not num:
            self.errors.append('La contrasena debe tener al menos un numero')
            return False
        else:
            return True

    def no_alfanumerico(self, passw):
        if passw.isalnum()==True:
            self.errors.append('La contrasena debe tener al menos un caracter no alfanumerico')
            return False
        else:
            return True

    def espacios(self, passw):
        if passw.count(" ")> 0:
            self.errors.append('La contrasena no puede contener espacios en blanco')
            return False
        else:
            return True

    def validar_password(self,passw):
        valido=self.longitud(passw) and self.minuscula(passw) and self.mayuscula(passw) and self.numero(passw) and self.no_alfanumerico(passw) and self.espacios(passw)
        return valido



validadorc


# -*- coding: utf-8 -*-
from Tkinter import *
import tkMessageBox
import usuarioc  as uv
import paswordc as pv

user_validator = uv.usuario_validar()
pass_validator = pv.password_validar()

def validation():
    cuser = user.get()
    cpasword = pasword.get()
    correcto = False


    if correcto == False:
        if not user_validator.validar_usuario(cuser):
            for error in user_validator.errors:
                tkMessageBox.showinfo("Aviso error usuario",error)
                correcto = False

                user_validator.errors.remove(error)
        else:
            correcto = True
            if correcto == True:
                if not pass_validator.validar_password(cpasword):
                    for error in pass_validator.errors:
                        tkMessageBox.showinfo("Aviso error contraseña",error)
                        correcto = True
                        pass_validator.errors.remove(error)
                else:
                    correcto = False
                    tkMessageBox.showinfo("Aviso", "Usuario y contraseña creados exitosamente")

raiz=Tk()
raiz.title("ventana primaria")
raiz.resizable(1,1) #para permitir agrandar o no el ancho o la altura con el moyuse
raiz.iconbitmap("descarga.ico")
#raiz.geometry("500x600")
raiz.config(bg="cyan")
raiz.config(bd=15)
raiz.config(relief="groove")

miFrame=Frame(raiz)
miFrame.pack()
miFrame.config(bg="pink")
miFrame.config(bd=10)
miFrame.config(relief="sunken")
miFrame.config(cursor="hand2")

miLabel1=Label(miFrame, text="Ingrese sus datos", fg="red",bg="pink",font=("Arial",18)).grid(row=0,column=0,pady="4")
nombreusuarioLabel=Label(miFrame, text="Nombre usuario: ",bg="pink").grid(row=3,column=0, sticky="w",pady="1")
contrasenaLabel=Label(miFrame, text="Contraseña: ",bg="pink").grid(row=4,column=0,sticky="w",pady="1")

user=StringVar()
pasword=StringVar()


cuadronombreusuario=Entry(miFrame, textvariable=user)
cuadronombreusuario.grid(row=3,column=1,pady="1")
cuadronombreusuario.config(fg="blue", justify="center")

cuadrocontrasena=Entry(miFrame, textvariable=pasword)
cuadrocontrasena.grid(row=4,column=1,pady="1")
cuadrocontrasena.config(show="*",fg="blue", justify="center")

botonEnvio=Button(raiz, text= "Enviar",command=validation)
botonEnvio.pack()


raiz.mainloop()

Interfaz:


Errores al ingresar los datos:






Datos ingresados de manera correcta:

Comprobacion del password y del usuario con metodos en TKinter.

# -*- coding: utf-8 -*-
from Tkinter import *
import tkMessageBox

def usercomp():
    cuser=user.get()
    longitud=len(cuser)
    notnum=cuser.isalnum()
    if notnum == False:
        tkMessageBox.showinfo("Error", "El nombre de usuario puede contener solo letras y números")
    elif longitud < 6:
        tkMessageBox.showinfo("Error","El nombre de usuario debe contener al menos 6 caracteres")
    elif longitud > 12:
        tkMessageBox.showinfo("Error", "El nombre de usuario no puede contener más de 12 caracteres")
    elif longitud > 5 and longitud < 13 and notnum == True:
        return True

def clavecomp():
    cpasword=pasword.get()
    validar = False  # que se vayan cumpliendo los requisitos uno a uno.
    long = len(cpasword)  # Calcula la longitud de la contraseña
    espacio = False  # variable para identificar espacios
    mayuscula = False  # variable para identificar letras mayúsculas
    minuscula = False  # variable para contar identificar letras minúsculas
    numeros = False  # variable para identificar números
    y = cpasword.isalnum()  # si es alfanumérica retona True
    correcto = True  # verifica que hayan mayuscula, minuscula, numeros y no alfanuméricos

    for carac in cpasword:  # ciclo for que recorre caracter por caracter en la contraseña

        if carac.isspace() == True:  # Saber si el caracter es un espacio
            espacio = True  # si encuentra un espacio se cambia el valor user

        if carac.isupper() == True:  # saber si hay mayuscula
            mayuscula = True  # acumulador o contador de mayusculas

        if carac.islower() == True:  # saber si hay minúsculas
            minuscula = True  # acumulador o contador de minúsculas

        if carac.isdigit() == True:  # saber si hay números
            numeros = True  # acumulador o contador de numeros

    if espacio == True:  # hay espacios en blanco
        tkMessageBox.showinfo("Error en la contraseña", "La contraseña no puede contener espacios")
    else:
        validar = True  # se cumple el primer requisito que no hayan espacios

    if long < 8 and validar == True:
        tkMessageBox.showinfo("Error en la contraseña ","Mínimo 8 caracteres")
        validar = False  # cambia a Flase si no se cumple el requisito móinimo de caracteres

    if mayuscula == True and minuscula == True and numeros == True and y == False and validar == True:
        validar = True  # Cumple el requisito de tener mayuscula, minuscula, numeros y no alfanuméricos
    else:
        correcto = False  # uno o mas requisitos de mayuscula, minuscula, numeros y no alfanuméricos no se cumple

    if validar == True and correcto == False:
        tkMessageBox.showinfo("Aviso",
            "La contraseña elegida no es segura: debe contener letras minúsculas, mayúsculas, números y al menos 1 carácter no alfanumérico")

    if validar == True and correcto == True:
        return True

def validation():
    correcto = False
    if correcto == False:

        if usercomp() == True:

            correcto = True

            if correcto == True:
                if clavecomp() == True:
                    tkMessageBox.showinfo("Aviso", "Usuario y contraseña creados exitosamente")
                    correcto = False

raiz=Tk()
raiz.title("ventana primaria")
raiz.resizable(1,1) #para permitir agrandar o no el ancho o la altura con el moyuse
raiz.iconbitmap("descarga.ico")
#raiz.geometry("500x600")
raiz.config(bg="cyan")
raiz.config(bd=15)
raiz.config(relief="groove")

miFrame=Frame(raiz)
miFrame.pack()
miFrame.config(bg="pink")
miFrame.config(bd=10)
miFrame.config(relief="sunken")
miFrame.config(cursor="hand2")

miLabel1=Label(miFrame, text="Ingrese sus datos", fg="red",bg="pink",font=("Arial",18)).grid(row=0,column=0,pady="4")
nombreusuarioLabel=Label(miFrame, text="Nombre usuario: ",bg="pink").grid(row=3,column=0, sticky="w",pady="1")
contrasenaLabel=Label(miFrame, text="Contraseña: ",bg="pink").grid(row=4,column=0,sticky="w",pady="1")

user=StringVar()
pasword=StringVar()


cuadronombreusuario=Entry(miFrame, textvariable=user)
cuadronombreusuario.grid(row=3,column=1,pady="1")
cuadronombreusuario.config(fg="blue", justify="center")

cuadrocontrasena=Entry(miFrame, textvariable=pasword)
cuadrocontrasena.grid(row=4,column=1,pady="1")
cuadrocontrasena.config(show="*",fg="blue", justify="center")

botonEnvio=Button(raiz, text= "Enviar",command=validation)
botonEnvio.pack()


raiz.mainloop()

Interfaz:


Errores:


Datos ingresados correctamente:

Interfaz con TKinter #2

# -*- coding: utf-8 -*-
from Tkinter import *
import Tkinter as tk

raiz=Tk()
raiz.title("ventana primaria")
raiz.resizable(1,1) #para permitir agrandar o no el ancho o la altura con el moyuse
raiz.iconbitmap("Hamburger.ico")
#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")
rtotal=Label(miFrame, text="_", bg="yellow",font=("Arial",14)).grid(row=7,column=2,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")
riva=Label(miFrame, text="_", bg="yellow",font=("Arial",14)).grid(row=8,column=2,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")
rtotalfinal=Label(miFrame, text="_", bg="yellow",font=("Arial",14)).grid(row=9,column=2,pady="1",padx="15", sticky="w")


#Lista de opciones despegable
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
listpedido=Listbox(miFrame, width=50).grid(row=2,column=2,pady="1",padx="4")

#Entrys
cuadrohamb=Entry(miFrame )
cuadrohamb.grid(row=2,column=1,pady="1")
cuadrohamb.config(fg="blue", justify="center")
cuadrorefresco=Entry(miFrame )
cuadrorefresco.grid(row=4,column=1,pady="1")
cuadrorefresco.config(fg="blue", justify="center")
cuadropapas=Entry(miFrame )
cuadropapas.grid(row=5,column=1,pady="1")
cuadropapas.config(fg="blue", justify="center")
cuadroburrito=Entry(miFrame )
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")
Cancelar.grid(row=10,column=0, sticky="w",padx="15")
Comprar=Button(miFrame, text= "Hacer pedido")
Comprar.grid(row=10,column=2, sticky="e",padx="15")
Terminar=Button(raiz, text= "Terminar")
Terminar.pack()

raiz.mainloop()