jueves, 14 de septiembre de 2017

Figuras

Figuras en Ventanas Hijas cada una 








  • Código
# -*- coding: utf-8 -*-from Tkinter import *
VentanaPrincipal= Tk()
VentanaPrincipal.title("Ventana Principal")
VentanaPrincipal.config(bg="DEEPPINK4")
VentanaPrincipal.geometry("400x400")

def ocultar(ventana):
    ventana.destroy()
def ejecutar(f):
    VentanaPrincipal.after(200, f)

def ventanas(num):
    venhija=Toplevel(VentanaPrincipal)
    venhija.title("Ventana")
    venhija.protocol("WM_DELETE_WINDOW", "onexit")
    venhija.geometry("500x500")
    if num==1:
        Circulo = Canvas(venhija, width=210, height=210, bg="Pale Green")
        Circulo.pack(expand=YES, fill=BOTH)
        Circulo.create_oval(10, 10, 200, 200, width=3, fill='Lawn Green')
        salir= Button(Circulo, text="Cerrar", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=3)
    elif num==2:
        Rectangulo = Canvas(venhija, width=210, height=210, bg="Light Cyan")
        Rectangulo.pack(expand=YES, fill=BOTH)
        Rectangulo.create_rectangle(10, 10, 200, 200, width=3, fill='Light Sea Green')
        salir= Button(Rectangulo, text="Cerrar", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=3)
    elif num==3:
        linea = Canvas(venhija, width=210, height=210, bg='white')
        linea.pack(expand=YES, fill=BOTH)
        linea.create_line(0, 200, 200, 0, width=10, fill='DEEPPINK2')
        linea.create_line(0, 0, 200, 200, width=10, fill='DEEPPINK2')
        salir= Button(linea, text="Cerrar", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=1)
    elif num==4:
        quesito = Canvas(venhija, width=300, height=200, bg='white')
        quesito.pack(expand=YES, fill=BOTH)
        quesito.create_arc(10, 10, 190, 190, start=270, extent=90, fill='DEEPPINK')
        salir= Button(quesito, text="Cerrar", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=3)
    elif num==5:
        arco = Canvas(venhija, width=300, height=200, bg='white')
        arco.pack(expand=YES, fill=BOTH)
        xy = 40, 40, 190, 190        arco.create_arc(xy, start=0, extent=270, fill='Light Pink')
        salir= Button(arco, text="Cerrar", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=3)
    elif num==6:
        Quecomp= Canvas(venhija, width=300, height=200, bg='white')
        Quecomp.pack(expand=YES, fill=BOTH)
        Quecomp.create_arc(60, 60, 200, 200, start=270, extent=90, fill='pink')
        Quecomp.pack(expand=YES, fill=BOTH)
        xy = 50, 50, 200, 200        Quecomp.create_arc(xy, start=0, extent=270, fill='yellow')
        salir= Button(Quecomp, text="Cerrar", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=3)
    elif num==7:
        texto = Canvas(venhija, width=300, height=200, bg='white')
        texto.pack(expand=YES, fill=BOTH)
        texto.create_text(150, 70, fill="DEEPPINK4", font="Arial 20", text="Edna Cordero Garcia \n  ISC")
        salir= Button(texto, text="Cerrar", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=1)
    elif num==8:
        CabMar= Canvas(venhija, width=200, height=10, bg="white")
        CabMar.pack(expand=YES, fill=BOTH)
        c = [35, 65, 50, 55, 50, 50, 47.5, 40, 50, 35, 45, 25, 55, 30, 50, 20, 62.5, 27.5, 70, 15, 72.5, 25,
             85, 15, 80, 27.5, 90, 25, 97.5, 27.5, 87.5, 32.5, 105, 35, 95, 47.5, 107.5, 52.5, 95, 62.5,
             107.5, 70, 95, 80, 105, 85, 90, 100, 97.5, 105, 82.5, 125, 92.5, 122.5, 105, 110, 110, 100,
             112.5, 115, 117.5, 122.5, 105, 127.5, 90, 132.5, 80, 135, 90, 137.5, 100, 135, 115, 130,
             112.5, 140, 117.5, 147.5, 95, 147.5, 75, 140, 85, 150, 95, 155, 115, 157.5, 100, 172.5,
             110, 180, 120, 195, 125, 205, 127.5, 215, 127.5, 235, 122.5, 255, 115, 275, 105, 290, 90, 300,
             75, 305, 60, 300, 50, 295, 40, 282.5, 37.5, 265, 39, 255, 45, 240, 55, 232.5, 65, 230, 75, 235,
             80, 240, 80, 250, 70, 260, 60, 262.5, 57.5, 250, 60, 245, 65, 245, 62.5, 250, 65, 255, 75, 250,
             75, 242.5, 65, 237.5, 55, 240, 50, 245, 46.5, 255, 45, 265, 47.5, 275, 55, 285, 65, 287.5,
             75, 287.5, 85, 282.5, 92.5, 275, 97.5, 265, 100, 255, 102.5, 245, 102.5, 235, 100, 225, 95, 215,
             85, 205, 75, 197.5, 65, 192.5, 55, 182.5, 47.5, 175, 40, 165, 32.5, 155, 30, 145, 30, 120, 35, 110,
             45, 100, 55, 90, 65, 80, 71, 71, 75, 60, 70, 55, 60, 60, 50, 65, 40, 67.5, 35, 65]
        for i in range(0, len(c)):
            c[i] = c[i] + 20        CabMar.create_polygon(c, fill="pink")
        salir= Button(CabMar, text="Cerrar (Carlos Guzman)", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=1)
    elif num==9:
        venado= Canvas(venhija, width=200, height=10, bg="Peach Puff")
        venado.pack(expand=YES, fill=BOTH)
        venado.create_polygon(150, 130, 135, 150, 140, 190, 155, 230, 180, 260, 200, 280, 195, 290, 160, 260, 120,
        250, 130, 295, 160, 310, 190, 310, 195, 360, 190, 420, 180, 430, 180, 455, 150, 470, 110, 560, 140,
                                 620, 180, 640,
                                 195, 660, 240, 640, 270, 610, 300, 590, 310, 540, 290, 465, 295, 410, 280, 360, 295,
                                 315, 320, 315,
                                 350, 295, 360, 250, 320, 260, 285, 290, 280, 280, 300, 255, 325, 230, 340, 190, 345,
                                 150, 330, 130,
                                 330, 170, 320, 160, 310, 160, 320, 170, 330, 190, 310, 220, 290, 250, 275, 260, 290,
                                 200, 270, 180,
                                 280, 200, 260, 270, 220, 270, 200, 200, 210, 180, 190, 200, 205, 260, 190, 250, 170,
                                 220, 150, 190,
                                 160, 170, 170, 160, 160, 160, 150, 170, 150, 130, fill="white")
        salir= Button(venado, text="Cerrar (Carlos Guzman)", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=1)
    elif num==10:
        mariposa = Canvas(venhija, width=300, height=300, bg="Pale Turquoise")
        mariposa.pack(expand=YES, fill=BOTH)
        mariposa.create_polygon(40, 20, 20, 60, 40, 100, 80, 120, 40, 160, 80, 220, 60, 240, 120, 220,
                                140, 140, 150, 180, 160, 140, 180, 220, 240, 240, 220, 220, 260, 160,
                                220, 120, 260, 100, 280, 60, 260, 20, 220, 30, 180, 60, 160, 100, 150, 80,
                                140, 100, 120, 60, 80, 30, 40, 20, fill="Lime Green")
        salir= Button(mariposa, text="Cerrar (Carlos Guzman)", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=1)
    elif num==11:
        caballo= Canvas(venhija, width=200, height=10, bg="black")
        caballo.pack(expand=YES, fill=BOTH)
        caballo.create_polygon(80, 10, 110, 40, 40, 100, 60, 100, 20, 140, 40, 140, 10, 190, 30, 190, 20, 220,
                                 50, 200, 60, 220, 40, 260, 140, 240, 190, 210, 170, 190, 150, 140, 160, 140,
                                 190, 150, 200, 150, 220, 140, 210, 110, 180, 80, 180, 70, 150, 30, 140, 30,
                                 120, 4, 120, 30, 80, 10, fill="PERU")
        salir= Button(caballo, text="Cerrar (Carlos Guzman)", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=1)
    elif num==12:
        estrella= Canvas(venhija, width=200, height=10, bg="Light Steel Blue")
        estrella.pack(expand=YES, fill=BOTH)
        estrella.create_polygon(130, 20, 150, 90, 210, 90, 160, 130, 180, 200, 130, 160, 80, 200,
                                 100, 130, 50, 90, 110, 90, fill="Light Gray")
        salir= Button(estrella, text="Cerrar (David Maldonado)", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=1)
    elif num==13:
        conejo= Canvas(venhija, width=390, height=350, bg='black')
        conejo.pack(expand=YES, fill=BOTH)
        puntos=[00, 20, 60, 20, 80, 80, 120, 80, 160, 20, 220, 40, 180, 40, 140, 80, 160, 100, 160, 120, 160, 140,
                  140, 160, 180, 180, 200, 200, 200, 240, 180, 280, 140, 300, 180, 320, 180, 340, 120, 340, 100, 320,
                  80, 340, 20, 340, 20, 320, 60, 300, 20, 280, 00, 240, 00, 200, 20, 180, 60, 160, 40, 140, 40, 120, 40,
                  100, 60, 80, 40, 40]
        conejo.create_polygon(puntos, fill="white")
        salir = Button(conejo, text="Cerrar(Lulu Brito)", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=1)
    elif num==14:
        manzana= Canvas(venhija, width=700, height=600, bg='white')
        manzana.pack(expand=YES, fill=BOTH)
        manzana.create_polygon((100, 200), (50, 250), (50, 300), (100, 250), (150, 300), (150, 250), (100, 200),
                                (150, 150), fill="green", outline="black", width=2)
        manzana.create_polygon((100, 100), (150, 50), (250, 50), (250, 150), (200, 200), (150, 150), fill="red",
                                outline="black", width=2)
        salir = Button(manzana, text="Cerrar(Edgar Mendez)", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=1)
    elif num==15:
        perrito = Canvas(venhija, width=300, height=200, bg='white')
        perrito.pack(expand=YES, fill=BOTH)
        perrito.create_polygon(180, 60,
                                 200, 80,
                                 180, 120,
                                 200, 140,
                                 240, 120,
                                 240, 180,
                                 260, 180,
                                 260, 140,
                                 300, 140,
                                 300, 180,
                                 320, 180,
                                 320, 120,
                                 340, 60,
                                 300, 100,
                                 240, 100,
                                 220, 80,
                                 fill="Burlywood", outline="black")
        salir = Button(perrito, text="Cerrar (Emmanuel Horta)", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=1)
    elif num==16:
        gato= Canvas(venhija, width=300, height=200, bg='white')
        gato.pack(expand=YES, fill=BOTH)
        gato.create_polygon(420, 180,420, 60,380, 100,300, 100,260, 60,260, 140,220, 100,
                              180, 100,140, 140,140, 80,150, 80,200, 40, 200, 20,160, 20,90, 80,100, 160,
                              120, 270,200, 270, 200, 230,160, 230,160, 210,180, 190,220, 190,220, 270,
                              280, 270,280, 230,260, 230,260, 180,400, 200,360, 220,320, 220,280, 180,
                              fill="Blue", outline="black", width=4)
        salir = Button(gato, text="Cerrar (Aquino Sanchez)", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=1)
    elif num==17:
            puntos = [226, 42, 198, 42, 170, 50, 141, 71, 127, 60, 108, 52, 94, 57, 85, 71, 85, 85, 95, 99, 108, 106,
                      120, 109, 127, 113, 127, 123, 142, 119, 161, 119, 178, 122, 189, 134, 192, 148, 189, 161, 176,
                      166, 160, 165, 142, 162, 156, 178, 170, 192, 192, 198, 207, 198, 198, 212, 170, 209, 151, 205,
                      132, 202, 113, 195, 108, 180, 99, 164, 80, 153, 57, 156, 38, 170, 34, 183, 35, 198, 42, 212, 56,
                      221, 71, 226, 85, 221, 104, 212, 127, 223, 152, 226, 175, 232, 189, 234, 184, 250, 184, 270, 184,
                      283, 190, 297, 196, 306, 184, 321, 180, 334, 178, 346, 180, 353, 188, 372, 212, 390, 194, 402,
                      181, 411, 170, 425, 170, 443, 176, 456, 190, 467, 208, 468, 227, 456, 275, 419, 276, 404, 269,
                      393, 252, 383, 236, 382, 221, 371, 206, 361, 201, 350, 203, 340, 209, 333, 221, 326, 237, 326,
                      255, 322, 270, 314, 280, 305, 297, 291, 311, 288, 335, 288, 354, 293, 368, 301, 378, 311, 386,
                      326, 403, 330, 411, 330, 462, 265, 461, 240, 450, 230, 435, 226, 421, 226, 406, 230, 396, 240,
                      380, 270, 354, 265, 332, 260, 311, 263, 297, 263, 283, 263, 278, 250, 264, 226, 283, 226, 297,
                      221, 312, 212, 330, 198, 346, 198, 363, 198, 375, 188, 382, 175, 386, 160, 382, 141, 362, 127,
                      334, 127, 326, 133, 312, 148, 312, 163, 315, 180, 304, 192, 290, 204, 273, 206, 255, 205, 241,
                      204, 234, 198, 255, 189, 269, 180, 278, 166, 286, 151, 291, 132, 292, 113, 289, 99, 283, 85, 280,
                      74, 269, 63, 255, 51, 234, 42]
            monito= Canvas(venhija, width=500, height=500, bg='white')
            monito.pack(expand=YES, fill=BOTH)
            monito.create_polygon(puntos, fill="black", outline="white", width=6)
            salir = Button(monito, text="Cerrar (Ricardo Castillo)", command=lambda: ejecutar(ocultar(venhija)))
            salir.grid(row=1, column=1)
    elif num==18:
        figura = Canvas(venhija)
        figura.config(width=400, height=600,bg='white')  # Lienzo con las medidas y color sobre el que se dibujará la figura        figura.pack(expand=YES, fill=BOTH)  # Sirve para cargar la figura
        figura.create_polygon(52.5, 14.5, 37, 59.1, 51, 59.1, fill="#5C554E", outline="#5C554E", width=1)
        figura.create_polygon(19.3, 56.8, 58, 59.1, 67, 91, 37.5, 83, fill="#C3BAB5", outline="#C3BAB5", width=1)
        figura.create_polygon(58, 57.8, 78, 77, 71, 103, fill="#D4CCC1", outline="#D4CCC1", width=1)
        figura.create_polygon(37.5, 83, 67.4, 91, 71, 103, fill="#998C8A", outline="#998C8A", width=1)
        figura.create_polygon(71, 103, 71, 104.8, 59.1, 104.8, 53.2, 91, fill="#665B57", outline="#665B57", width=1)

        figura.create_polygon(86, 105.6, 98.2, 148.6, 47, 133.6, 24.2, 103.6, fill="#C3BAB5", outline="#C3BAB5",
                              width=1)
        figura.create_polygon(98.2, 148.6, 102, 165.2, 47, 133.6, fill="#9B8D8A", outline="#9B8D8A", width=1)
        figura.create_polygon(86, 105.6, 124, 169, 120, 196, 110.8, 196, fill="#D5CDC2", outline="#D5CDC2", width=1)
        figura.create_polygon(102, 165.2, 110.8, 196, 99, 196, 80.6, 153, fill="#605550", outline="#605550", width=1)

        figura.create_polygon(139.5, 197, 147, 241, 71, 220.4, 46, 193, fill="#C3BAB5", outline="#C3BAB5", width=1)
        figura.create_polygon(147, 241, 150, 261.4, 71, 220.4, fill="#968B87", outline="#968B87", width=1)
        figura.create_polygon(139.5, 197, 193, 274.2, 189, 307.8, 176, 321, 161.6, 321, fill="#D4CCC1",
                              outline="#D4CCC1", width=1)
        figura.create_polygon(150, 261.4, 161.6, 321, 126.8, 249, fill="#605551", outline="#605551", width=1)

        figura.create_polygon(199.4, 307.8, 189, 307.8, 176, 321, 186.6, 461, 184, 448.8, 171, 479.5, 199.4, 503,
                              fill="#C2AD9C", outline="#C2AD9C", width=1)
        figura.create_polygon(176, 321, 161.6, 321, 186.6, 461, fill="#615652", outline="#615652", width=1)
        figura.create_polygon(161.6, 321, 136, 359.4, 177.2, 409, fill="#D9C6B7", outline="#D9C6B7", width=1)
        figura.create_polygon(144.4, 369.8, 139.6, 384.6, 160, 389.4, fill="#443232", outline="#443232", width=1)
        figura.create_polygon(139.6, 384.6, 160, 389.4, 177.2, 409, 169.2, 450, fill="#826E65", outline="#826E65",
                              width=1)
        figura.create_polygon(171, 479.5, 180.6, 497.8, 191.2, 496.8, fill="#463334", outline="#463334", width=1)
        figura.create_polygon(177.2, 409, 164.8, 475, 176.5, 511, 199.4, 522, 199.4, 502.8, 191.2, 496.8, 180.6, 497.8,
                              171, 479.5, 184, 448.8, fill="#9B7F79", outline="#9B7F79", width=1)

        figura.create_polygon(151.8, 335.4, 109.6, 280, 142.2, 349.2, fill="#5F5150", outline="#5F5150", width=1)
        figura.create_polygon(109.6, 280, 70.3, 266, 94.3, 329, 131.3, 326, fill="#483636", outline="#483636", width=1)
        figura.create_polygon(94.3, 329, 137, 336, 132, 326.8, fill="#C2AF9D", outline="#C2AF9D", width=1)
        figura.create_polygon(115, 333, 136, 359.4, 142.2, 349.2, 137, 336, fill="#826E65", outline="#826E65", width=1)

        # Lado inverso        figura.create_polygon(346.5, 14.5, 347.5, 59.1, 361, 59.1, fill="#2E2621", outline="#2E2621", width=1)
        figura.create_polygon(379.4, 56.8, 341.8, 59.1, 332, 91, 361, 83, fill="#908782", outline="#908782", width=1)
        figura.create_polygon(341.5, 57.8, 324, 75, 327.6, 103, fill="#A29B8F", outline="#A29B8F", width=1)
        figura.create_polygon(361, 83, 332.4, 91, 329, 103, fill="#685D59", outline="#685D59", width=1)
        figura.create_polygon(329, 103, 326.8, 104.8, 340, 104.8, 345.6, 91, fill="#2D2220", outline="#2D2220", width=1)

        figura.create_polygon(313, 105.6, 301, 148.6, 352, 133.6, 374.5, 103.6, fill="#908782", outline="#908782",
                              width=1)
        figura.create_polygon(301, 148.6, 297, 165.2, 352, 133.6, fill="#625755", outline="#625755", width=1)
        figura.create_polygon(313, 105.6, 274, 169, 279, 196, 288, 196, fill="#A1998E", outline="#A1998E", width=1)
        figura.create_polygon(297, 165.2, 288, 196, 300, 196, 318, 153, fill="#2D221E", outline="#2D221E", width=1)

        figura.create_polygon(260, 197, 252, 241, 331, 220.4, 352.4, 193, fill="#908782", outline="#908782", width=1)
        figura.create_polygon(252, 241, 249, 261.4, 331, 220.4, fill="#645955", outline="#645955", width=1)
        figura.create_polygon(260, 197, 205, 274.2, 209.8, 307.8, 223, 321, 238, 321, fill="#A1998E", outline="#A1998E",
                              width=1)
        figura.create_polygon(249, 261.4, 238.6, 321, 271.8, 249, fill="#2D221E", outline="#2D221E", width=1)

        figura.create_polygon(199.4, 307.8, 209.8, 307.8, 223, 321, 212.6, 461, 215, 448.8, 228, 479.5, 199.4, 503,
                              fill="#8E7968", outline="#8E7968", width=1)
        figura.create_polygon(223, 321, 238.6, 321, 212.6, 461, fill="#302722", outline="#302722", width=1)
        figura.create_polygon(238, 321, 262.8, 359.4, 222.5, 409, fill="#A69384", outline="#A69384", width=1)
        figura.create_polygon(254.4, 369.8, 259.6, 384.6, 238, 389.4, fill="#120001", outline="#120001", width=1)
        figura.create_polygon(259.6, 384.6, 238, 389.4, 222.5, 409, 229.5, 450, fill="#4F3B32", outline="#4F3B32",
                              width=1)
        figura.create_polygon(228, 479.5, 218.3, 497.8, 207.5, 496.8, fill="#180A04", outline="#180A04", width=1)
        figura.create_polygon(222.5, 409, 234, 475, 223, 511, 199.4, 522, 199.4, 502.8, 207.5, 496.8, 218.3, 497.8, 228,
                              479.5, 215, 448.8, fill="#674C45", outline="#674C45", width=1)

        figura.create_polygon(247, 335.4, 290.6, 280, 256.8, 349.2, fill="#281F1D", outline="#281F1D", width=1)
        figura.create_polygon(290.6, 280, 328, 266, 304.8, 329, 267.5, 326, fill="#140202", outline="#140202", width=1)
        figura.create_polygon(304.8, 329, 262.5, 336, 267.5, 326.8, fill="#8D7B66", outline="#8D7B66", width=1)
        figura.create_polygon(283, 333, 262.8, 359.4, 256.8, 349.2, 262.5, 336, fill="#4D3930", outline="#4D3930",
                              width=1)
        salir = Button(figura, text="Cerrar (David Mendoza)", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=1)

    elif num == 19:
        mifig = Canvas(venhija, width=300, height=200, bg='white')
        mifig.pack(expand=YES, fill=BOTH)
        mifig.create_polygon(50, 80,
                                 70, 60,
                                 70, 53.8,
                                 80, 40,
                                 80, 30,
                                 120, 80,
                                 180, 80,
                                 190, 90,
                                 200, 80,
                                 220, 90,
                                 210, 140,
                                 210, 160,
                                 200, 140,
                                 200, 100,
                                 190, 100,
                                 190, 200,
                                 170, 200,
                                 180, 190,
                                 180, 150,
                                 160, 130,
                                 120, 130,
                                 110, 140,
                                 110, 200,
                                 90, 200,
                                 100, 190,
                                 100, 140,
                                 90, 120,
                                 90, 100,
                                 80, 80,
                                 70, 80,
                                 60, 90,

                                 fill="PERU", outline="Saddle Brown")
        salir = Button(mifig, text="Cerrar", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=1)

    elif num == 20:
        poligono = Canvas(venhija, width=300, height=200, bg='white')
        poligono.pack(expand=YES, fill=BOTH)
        poligono.create_polygon(40, 40, 40, 140, 140, 140, 140, 100, fill="Orchid", outline="deeppink")
        salir = Button(poligono, text="Cerrar", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=1)

    elif num == 21:
        fb = Canvas(venhija, width=300, height=200, bg='white')
        fb.pack(expand=YES, fill=BOTH)
        fb.create_polygon(
            15, 18,
            180, 17.4,
            180, 180,
            129.8, 179.4,
            130.2, 114.2,
            151, 114,
            151.2, 92.6,
            129.8, 91.6,
            129.6, 72.4,
            132.6, 68.2,
            135.6, 65.2,
            140, 64.2,
            153.4, 63.8,
            153, 44.2,
            128, 43.2,
            122, 44.2,
            117.4, 46.8,
            114.2, 50.8,
            110.8, 53.4,
            108.8, 57.4,
            106.4, 62.4,
            105.8, 67,
            106.4, 92,
            84.8, 92.2,
            85, 113.8,
            105.6, 114.2,
            105.8, 179.4,
            15.2, 180,
            fill="lightblue", outline="blue", width=6)
        salir = Button(fb, text="Cerrar (Juan Garcia)", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=5)

    elif num == 22:
        corazon = Canvas(venhija, width=210, height=210, bg='white')
        corazon.pack(expand=YES, fill=BOTH)
        corazon.create_polygon(150, 150, 200, 100, 250, 100, 300, 150, 350, 100, 400, 100, 450, 150, 435, 200, 300, 350,
                               180, 201, fill="red", outline="black", width=6)
        salir = Button(corazon, text="Cerrar (Uriel Vega)", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=5)

    elif num == 23:
        poly = Canvas(venhija, width=210, heigh=210, bg='White')
        poly.pack(expand=YES, fill=BOTH)
        poly.create_polygon(50, 20, 100, 20, 100, 30, 130, 30, 130, 40, 110, 40, 110, 50, 130, 50, 130, 60, 140, 60,
                            140, 70, 130, 70, 130, 80, 120, 80, 120, 90, 100, 90, 100, 100, 130, 100, 130, 110, 140,
                            110, 140, 150, 120, 150, 120, 160, 130, 160, 130, 170, 140, 170, 140, 180, 100, 180, 100,
                            160, 90, 160, 90, 150, 70, 150, 70, 160, 60, 160, 60, 180, 20, 180, 20, 170, 30, 170, 30,
                            160, 40, 160, 40, 150, 20, 150, 20, 110, 30, 110, 30, 100, 40, 100, 40, 90, 50, 90, 50, 80,
                            30, 80, 30, 50, 40, 50, 40, 30, 50, 30, fill="red", outline='white')
        salir = Button(poly, text="Cerrar (Jonathan Guzman)", command=lambda: ejecutar(ocultar(venhija)))
        salir.grid(row=1, column=5)

    venhija.deiconify()


boton1= Button(VentanaPrincipal, text="Circulo", command=lambda: ejecutar(ventanas(1)))
boton1.grid(row=1, column=1)
boton2= Button(VentanaPrincipal, text="Rectangulo", command=lambda: ejecutar(ventanas(2)))
boton2.grid(row=1, column=2)
boton3= Button(VentanaPrincipal, text="Lineas", command=lambda: ejecutar(ventanas(3)))
boton3.grid(row=4, column=3)
boton5= Button(VentanaPrincipal, text="Quesito", command=lambda: ejecutar(ventanas(4)))
boton5.grid(row=1, column=4)
boton6= Button(VentanaPrincipal, text="Arco", command=lambda: ejecutar(ventanas(5)))
boton6.grid(row=1, column=3)
boton7= Button(VentanaPrincipal, text="QuesitoCompleto", command=lambda: ejecutar(ventanas(6)))
boton7.grid(row=1, column=5)
boton8= Button(VentanaPrincipal, text="Texto", command=lambda: ejecutar(ventanas(7)))
boton8.grid(row=3, column=3)
boton4= Button(VentanaPrincipal, text="MiFigura", command=lambda: ejecutar(ventanas(19)))
boton4.grid(row=4, column=2)
boton9= Button(VentanaPrincipal, text="CaballitoMar", command=lambda: ejecutar(ventanas(8)))
boton9.grid(row=3, column=5)
boton10= Button(VentanaPrincipal, text="Venado", command=lambda: ejecutar(ventanas(9)))
boton10.grid(row=4, column=4)
boton11= Button(VentanaPrincipal, text="Mariposa", command=lambda: ejecutar(ventanas(10)))
boton11.grid(row=3, column=2)
boton12= Button(VentanaPrincipal, text="Caballo", command=lambda: ejecutar(ventanas(11)))
boton12.grid(row=3, column=4)
boton13= Button(VentanaPrincipal, text="Estrella", command=lambda: ejecutar(ventanas(12)))
boton13.grid(row=2, column=4)
boton14= Button(VentanaPrincipal, text="Conejo", command=lambda: ejecutar(ventanas(13)))
boton14.grid(row=3, column=1)
boton15= Button(VentanaPrincipal, text="Manzana", command=lambda: ejecutar(ventanas(14)))
boton15.grid(row=4, column=5)
boton16= Button(VentanaPrincipal, text="Perrito", command=lambda: ejecutar(ventanas(15)))
boton16.grid(row=2, column=1)
boton17= Button(VentanaPrincipal, text="Gato", command=lambda: ejecutar(ventanas(16)))
boton17.grid(row=2, column=3)
boton18= Button(VentanaPrincipal, text="Monito", command=lambda: ejecutar(ventanas(17)))
boton18.grid(row=4, column=1)
boton19= Button(VentanaPrincipal, text="VenadoPhotoshop", command=lambda: ejecutar(ventanas(18)))
boton19.grid(row=2, column=5)
boton19= Button(VentanaPrincipal, text="Poligono", command=lambda: ejecutar(ventanas(20)))
boton19.grid(row=2, column=2)
boton20= Button(VentanaPrincipal, text="Facebook", command=lambda: ejecutar(ventanas(21)))
boton20.grid(row=1, column=6)
boton21= Button(VentanaPrincipal, text="Corazon", command=lambda: ejecutar(ventanas(22)))
boton21.grid(row=2, column=6)
boton22= Button(VentanaPrincipal, text="MarioBros", command=lambda: ejecutar(ventanas(23)))
boton22.grid(row=3, column=6)

VentanaPrincipal.mainloop()




miércoles, 13 de septiembre de 2017

JUEGO DEL GATO

JUEGO DEL GATO



  • Código

from Tkinter import *
import tkMessageBox
import tkSimpleDialog


def bloq():
    for i in range(0, 9):
        lisb[i].config(state="disable")


def inij():
    for i in range(0, 9):
        lisb[i].config(state="normal")
        lisb[i].config(bg="white")
        lisb[i].config(text="")
        tab[i] = "N"    global nomj1, nomj2  # indica a que variables queremos acceder    nomj1 = tkSimpleDialog.askstring("Jugador", "Jugador 1: ")
    nomj2 = tkSimpleDialog.askstring("Jugador", "Jugador 2: ")
    turj.set("Turno: " + nomj1)


def cam(num):
    global turno, nomj1, nomj2
    if tab[num] == "N" and turno == 0:
        lisb[num].config(text="X")
        lisb[num].config(bg="pink")
        tab[num] = "X"        turno = 1        turj.set("Turno: " + nomj2)
    elif tab[num] == "N" and turno == 1:
        lisb[num].config(text="O")
        lisb[num].config(bg="DEEPPINK")
        tab[num] = "O"        turno = 0        turj.set("Turno: " + nomj1)
    lisb[num].config(state="disable")
    verif()


def verif():
    if (tab[0] == "X" and tab[1] == "X" and tab[2] == "X") or (tab[3] == "X" and tab[4] == "X" and tab[5] == "X") or (
                tab[6] == "X" and tab[7] == "X" and tab[8] == "X"):
        bloq()
        tkMessageBox.showinfo("Ganaste", "Ganaste: " + nomj1)
    elif (tab[0] == "X" and tab[3] == "X" and tab[6] == "X") or (tab[1] == "X" and tab[4] == "X" and tab[7] == "X") or (
                tab[2] == "X" and tab[5] == "X" and tab[8] == "X"):
        bloq()
        tkMessageBox.showinfo("Ganaste", "Ganaste: " + nomj1)
    elif (tab[0] == "X" and tab[4] == "X" and tab[8] == "X") or (tab[2] == "X" and tab[4] == "X" and tab[6] == "X"):
        bloq()
        tkMessageBox.showinfo("Ganaste", "Ganaste: " + nomj1)
    elif (tab[0] == "O" and tab[1] == "O" and tab[2] == "O") or (tab[3] == "O" and tab[4] == "O" and tab[5] == "O") or (
                tab[6] == "O" and tab[7] == "O" and tab[8] == "O"):
        bloq()
        tkMessageBox.showinfo("Ganaste", "Ganaste: " + nomj2)
    elif (tab[0] == "O" and tab[3] == "O" and tab[6] == "O") or (tab[1] == "O" and tab[4] == "O" and tab[7] == "O") or (
                tab[2] == "O" and tab[5] == "O" and tab[8] == "O"):
        bloq()
        tkMessageBox.showinfo("Ganaste", "Ganaste: " + nomj2)
    elif (tab[0] == "O" and tab[4] == "O" and tab[8] == "O") or (tab[2] == "O" and tab[4] == "O" and tab[6] == "O"):
        bloq()
        tkMessageBox.showinfo("Ganaste", "Ganaste: " + nomj2)



ven = Tk()
ven.geometry("370x460")
ven.config(bg="DEEPPINK4")
ven.title("Juego del gato")
turno = 0
nomj1 = ""nomj2 = ""
lisb = []
tab = []
turj = StringVar()

for i in range(0, 9):
    tab.append("N")

b0 = Button(ven, width=9, height=3, relief=SOLID, cursor="pencil", command=lambda: cam(0))
lisb.append(b0)
b0.place(x=50, y=50)
b1 = Button(ven, width=9, height=3, relief=SOLID, cursor="pencil", command=lambda: cam(1))
lisb.append(b1)
b1.place(x=150, y=50)
b2 = Button(ven, width=9, height=3, relief=SOLID, cursor="pencil", command=lambda: cam(2))
lisb.append(b2)
b2.place(x=250, y=50)
b3 = Button(ven, width=9, height=3, relief=SOLID, cursor="pencil", command=lambda: cam(3))
lisb.append(b3)
b3.place(x=50, y=150)
b4 = Button(ven, width=9, height=3, relief=SOLID, cursor="pencil", command=lambda: cam(4))
lisb.append(b4)
b4.place(x=150, y=150)
b5 = Button(ven, width=9, height=3, relief=SOLID, cursor="pencil", command=lambda: cam(5))
lisb.append(b5)
b5.place(x=250, y=150)
b6 = Button(ven, width=9, height=3, relief=SOLID, cursor="pencil", command=lambda: cam(6))
lisb.append(b6)
b6.place(x=50, y=250)
b7 = Button(ven, width=9, height=3, relief=SOLID, cursor="pencil", command=lambda: cam(7))
lisb.append(b7)
b7.place(x=150, y=250)
b8 = Button(ven, width=9, height=3, relief=SOLID, cursor="pencil", command=lambda: cam(8))
lisb.append(b8)
b8.place(x=250, y=250)
tue = Label(ven, textvariable=turj).place(x=140, y=10)
bini = Button(ven, bg='DEEPPINK3', fg='white', text='Iniciar', cursor="sizing", width=15, height=3,
              command=inij).place(x=130, y=360)
bloq()

linea = Canvas(ven, width=310, height=10)
linea.place(x=30, y=120)
linea.create_line(310, 0, 0, 0, width=25, fill='white')
l2 = Canvas(ven, width=310, height=10)
l2.place(x=30, y=220)
l2.create_line(310, 0, 0, 0, width=25, fill='white')
l3 = Canvas(ven, width=10, height=310)
l3.place(x=130, y=25)
l3.create_line(0, 310, 0, 0, width=25, fill='white')
l4 = Canvas(ven, width=10, height=310)
l4.place(x=230, y=25)
l4.create_line(0, 310, 0, 0, width=25, fill='white')

ven.mainloop()

martes, 12 de septiembre de 2017

Librería TURTLE

Librería TURTLE

Figura:

  • Corazón


Código:

from turtle import *
def curvemove():
    for i in range(200):
        right(1)
        forward(1)
color('deeppink4','deeppink')
begin_fill()
left(140)
forward(111.65)
curvemove()
left(120)
curvemove()
forward(111.65)
end_fill()
done()



CIRCULO, RECTÁNGULO Y LINEA EN VENTANAS HIJAS

CIRCULO, RECTÁNGULO Y LINEA EN VENTANAS HIJAS 



  • CÓDIGO:


# -*- coding: utf-8 -*-from Tkinter import *
ventanap = Tk()
ventanap.config(bg="DEEPPINK4")
ventanap.geometry("500x500")
ventanap.title("Ventana")
vencir = Toplevel(ventanap)
vencir.protocol("WM_DELETE_WINDOW", "onexit")

venrec = Toplevel(ventanap)
venrec.protocol("WM_DELETE_WINDOW", "onexit")

venlin = Toplevel(ventanap)
venlin.protocol("WM_DELETE_WINDOW", "onexit")

def ejecutar(f):
 vencir.after(200, f)

def ejecutar2(f):
 venrec.after(200, f)

def ejecutar3(f):
 venlin.after(200, f)

def mostrar(ventana):
 ventana.deiconify()

def circulo(ven):
 circulo = Canvas(vencir, width=210, height=210, bg="DEEPPINK2")
 circulo.pack(expand=YES, fill=BOTH)
 circulo.create_oval(10, 10, 200, 200, width=3, fill='PINK')
 vencir.deiconify()

def rectangulo(ven):
 rectangulo = Canvas(venrec, width=210, height=210, bg="pink")
 rectangulo.pack(expand=YES, fill=BOTH)
 rectangulo.create_rectangle(10, 10, 200, 200, width=3, fill='DEEPPINK')
 venrec.deiconify()

def linea(ven):
 linea = Canvas(venlin, width=210, height=210, bg="white")
 linea.pack(expand=YES, fill=BOTH)
 linea.create_line(5, 5, 200, 200, width=3, fill='DEEPPINK2')
 venlin.deiconify()

def ocultar(ventana):
 vencir.withdraw()
 venrec.withdraw()
 venlin.withdraw()

salir1= Button(vencir, text="Cerrar", command=lambda: ejecutar(ocultar(vencir)))
salir1.pack()
salir2= Button(venrec, text="Cerrar", command=lambda: ejecutar2(ocultar(venrec)))
salir2.pack()
salir3= Button(venlin, text="Cerrar", command=lambda: ejecutar3(ocultar(venlin)))
salir3.pack()

botoncir = Button(ventanap, text="ver circulo",command=lambda: ejecutar (circulo(ventanap))) # Primer boton
botoncir.grid(row=1, column=1) # El botón es cargado
botonrec = Button(ventanap, text="ver rectangulo",command=lambda: ejecutar (rectangulo(ventanap))) # Primer boton
botonrec.grid(row=1, column=2) # El botón es cargado
botonlin = Button(ventanap, text="ver linea",command=lambda: ejecutar (linea(ventanap))) # Primer boton
botonlin.grid(row=1, column=3) # El botón es cargadovencir.withdraw()
venrec.withdraw()
venlin.withdraw()
ventanap.mainloop()





martes, 5 de septiembre de 2017

Ejercicio 8

EJERCICIO 8

Abrir, ocultar y salir de una Segunda Ventana


  • Código

#!/usr/bin/env python# -*- coding: utf-8 -*-
from Tkinter import *  # Importa el módulo
ventanap = Tk()  # Tk() Es la ventana principalventanap.title("Ventana Principal")
ventanap.config(bg="DEEPPINK4")  # Le da color al fondoventanap.geometry("500x500")  # Cambia el tamaño de la ventana


venthija = Toplevel(ventanap)  # Crea una ventana hijaventhija.title("Ventana hija")
venthija.config(bg="DEEPPINK2")
venthija.geometry("250x250")
venthija.protocol("WM_DELETE_WINDOW", "onexit")  # Elimina la opción de salir para evitar el error

def mostrar(ventana): ventana.deiconify()  # Muestra una ventana

def ocultar(ventana): ventana.withdraw()  # Oculta una ventana

def ejecutar(f): ventanap.after(200, f)  # Una forma de ejecutar las funciones

def imprimir(texto): print texto  # Imprime un texto
boton1 = Button(ventanap, text="Abrir segunda ventana",
                command=lambda: ejecutar(mostrar(venthija)) or imprimir("hola") or imprimir("tercera función"))  # Primer botónboton1.grid(row=1, column=1)  # El botón es cargado

boton2 = Button(venthija, text="Ocultar segunda ventana", command=lambda: ejecutar(ocultar(venthija)))  # Segundo botónboton2.grid(row=1, column=2)  # El botón es cargado
boton3 = Button(ventanap, text="SALIR", command=lambda: ejecutar(ocultar(venthija)))
boton3.grid(row=1, column=2)  # El botón es cargado
venthija.withdraw()  # Oculta la ventana v1ventanap.mainloop()  # Es el evento que llama al inicio de nuestro programa. Siempre lo lleva la ventana principal.

  • Pantalla de Corrida

Programas del VIDEO #12 PYTHON

Ejercicios del VIDEO #12  Tutorial PYTHON

Utilizando la palabra reservada "def"








Definición de Función

Definición de Función

En programación, una función es un grupo de instrucciones con un objetivo en particular y que se ejecuta al ser llamada desde otra función o procedimiento. Una función puede llamarse múltiples veces e incluso llamarse a sí misma.

Las funciones pueden recibir datos desde afuera al ser llamadas a través de los parámetros y deben entregar un resultado.

Se diferencian de los procedimientos porque estos no devuelven un resultado.

En general las funciones deben tener un nombre único en el ámbito para poder ser llamadas, un tipo de dato de resultado, una lista de parámetros de entrada y su código.


Palabra reservada def

 La sintaxis para una definición de función en Python es:
def NOMBRE( LISTA DE PARAMETROS ):
    SENTENCIAS

En una definición de función la palabra reservada en el encabezado es def, y enseguida se escribe el nombre de la función y una lista de parámetros encerrados entre paréntesis. La lista de parámetros puede estar vacía o contener un sinnúmero de parámetros. En cualquier caso los paréntesis se requieren.
El primer par de funciones que escribiremos no tiene parámetros, por lo que la sintaxis luce así:
def nueva_linea():
    print        # la sentencia print sin argumentos muestra una nueva línea

sábado, 2 de septiembre de 2017

PRIMER PROGRAMA CON IDE

PRIMER PROGRAMA CON IDE


ABRIR, CENTRAR Y OCULTAR VENTANA (BOTÓN)

#!/usr/bin/env python# -*- coding: utf-8 -*-
from Tkinter import * # Importa el módulo
ventana1 = Tk()
ventana1.title("PRIMER IDE")
ventana2=Toplevel(ventana1)

def mostrar(ventana): ventana.deiconify()
def centrar(ventana):
    ventana.update_idletasks()
    w=ventana.winfo_width()
    h=ventana.winfo_height()
    extraW=ventana.winfo_screenwidth()-w
    extraH=ventana.winfo_screenheight()-h
    ventana.geometry("%dx%d%+d%+d" % (w,h,extraW/2,extraH/2))
def ocultar(ventana):ventana.withdraw()
def ejecutar(f): ventana1.after(200,f)

ventana1.config(bg="DeepPink4")
ventana1.geometry("500x500")

boton1=Button(ventana1,text="ABRIR VENTANA ",command=lambda: ejecutar(mostrar(ventana2)))
boton1.grid(row=1,column=1)
boton3=Button(ventana1,text="CENTRAR VENTANA",command=lambda: ejecutar(centrar(ventana2)))
boton3.grid(row=1,column=3)
boton2=Button(ventana1,text="OCULTAR VENTANA",command=lambda: ejecutar(ocultar(ventana2)))
boton2.grid(row=1,column=2)

ventana2.withdraw()
ventana1.mainloop()




CÓDIGO PARA UTILIZAR ACENTOS Y LA LETRA "Ñ" EN PYTHON


#!/usr/bin/env python
# -*- coding: utf-8 -*-

Manual TKINTER

MANUAL/GUÍA TKINTER

  • https://media.readthedocs.org/pdf/guia-tkinter/latest/guia-tkinter.pdf
  • http://guia-tkinter.readthedocs.io/es/develop/chapters/5-basic/5.1-Intro.html
  • http://infohost.nmt.edu/tcc/help/pubs/tkinter/tkinter.pdf (INGLÉS)

Liga de Ejemplos en PYTHON

  • http://www.comoprogramar.org/ejemplos-de-python-codigo/
  • https://www.discoduroderoer.es/ejercicios-propuestos-y-resueltos-basicos-en-python/
  • http://www.fcaglp.unlp.edu.ar/~observacional/manuales/python-by-vilar.pdf