Tarea 9 Unidad 2: Antologia de Dibujos Tkinter

El dia de hoy veremos un programa que recopila varias figuras creadas en Tkinter de mis compañeros de clase:

codigo:


from Tkinter import *

def eleccion(opc,nombre):
    vs=Toplevel()
    vs.configure(bg="gray")
    vs.title(nombre)
    if opc==1:
        panel = Canvas(vs,width=1200, height=650, bg="gray")
        panel.pack()
        # cara
        panel.create_polygon(415, 50, 235, 490, 365, 625, 755, 625, 850, 500, 700, 50,
                             width=1, fill="#e0af77", outline="brown")
        # orejas
        panel.create_polygon(415, 50, 60, 320, 175, 635, width=1, fill="#bb6400", outline="#000000")
        panel.create_polygon(700, 50, 1045, 320, 896, 635, width=1, fill="#bb6400", outline="#000000")
        # menton
        panel.create_polygon(365, 625, 550, 415, 755, 625, width=1, fill="#bb6400", outline="#000000")
        # ojos
        panel.create_oval(420, 225, 480, 305, width=1, fill="#1a1200", outline="#000000")
        panel.create_oval(630, 225, 690, 305, width=1, fill="#1a1200", outline="#000000")
        # bigotes
        panel.create_oval(475, 525, 490, 540, width=1, fill="#1a1200", outline="#000000")
        panel.create_oval(615, 525, 630, 540, width=1, fill="#1a1200", outline="#000000")
        panel.create_oval(445, 560, 460, 575, width=1, fill="#1a1200", outline="#000000")
        panel.create_oval(610, 560, 625, 575, width=1, fill="#1a1200", outline="#000000")
        panel.create_oval(480, 560, 495, 575, width=1, fill="#1a1200", outline="#000000")
        panel.create_oval(640, 560, 655, 575, width=1, fill="#1a1200", outline="#000000")
        # nariz
        panel.create_oval(470, 305, 640, 500, width=1, fill="#1a1200", outline="#000000")
    elif opc==2:
        panel = Canvas(vs,width=500, height=450, bg="gray")
        panel.pack()
        # cara
        panel.create_polygon(200, 80, 120, 240, 120, 260, 140, 300, 160, 310, 240, 310, 310, 290, 350, 280, 360, 250,
                             350, 230,
                             340, 210, 250, 80,
                             width=1, fill="yellow", outline="black")
        # cejas
        panel.create_polygon(150, 190, 142, 200, 175, 225, 185, 210, width=1, fill="black", outline="black")
        panel.create_polygon(200, 210, 210, 220, 248, 205, 240, 190, width=1, fill="black", outline="black")
        # boca
        panel.create_polygon(150, 250, 150, 260, 185, 255, 170, 263,
                             173, 275, 205, 263, 200, 240, width=2, fill="orange", outline="black")
        # ojos
        panel.create_oval(210, 215, 255, 235, width=1, fill="white", outline="black")
        panel.create_oval(140, 218, 175, 235, width=1, fill="white", outline="black")
        # pupilas
        panel.create_oval(215, 215, 235, 235, width=1, fill="black", outline="black")
        panel.create_oval(140, 218, 160, 235, width=1, fill="black", outline="black")
        # cabello
        panel.create_polygon(200, 80, 210, 75, 210, 60, 220, 50, 220, 70, 230, 50, 240, 50,
                             240, 60, 230, 70, 255, 65, 260, 70, 240, 78,
                             260, 80, 230, 88, width=1, fill="black", outline="black")
    elif opc==3:
        panel = Canvas(vs,width=500, height=450, bg="skyblue")
        panel.pack()
        # cara
        panel.create_oval(120, 80, 320, 200, width=2, fill="chocolate", outline="black")

        # ojos
        panel.create_oval(180, 100, 200, 130, width=1, fill="black", outline="black")
        panel.create_oval(240, 100, 260, 130, width=1, fill="black", outline="black")

        # pupila
        panel.create_oval(185, 105, 190, 115, width=1, fill="white", outline="black")
        panel.create_oval(245, 105, 250, 115, width=1, fill="white", outline="black")

        # boca
        panel.create_arc(170, 140, 270, 180, extent=180, style=CHORD, start=180, width=2, fill="black", outline="black")

        # sonrisa rosybrown
        panel.create_arc(155, 145, 190, 160, extent=100, style=ARC, start=180, width=2, fill="black", outline="black")
        panel.create_arc(255, 145, 290, 160, extent=100, style=ARC, start=255, width=2, fill="black", outline="black")
        panel.create_oval(195, 170, 245, 180, width=2, fill="pink2", outline="black")

        # Petalos
        panel.create_arc(200, 30, 240, 130, extent=180, start=0, style=CHORD, width=2, fill="yellow2", outline="black")
        panel.create_arc(240, 40, 280, 130, extent=180, start=353, style=CHORD, width=2, fill="yellow2",
                         outline="black")
        panel.create_arc(275, 58, 315, 145, extent=185, start=340, style=CHORD, width=2, fill="yellow2",
                         outline="black")
        panel.create_arc(255, 100, 365, 140, extent=190, start=280, style=CHORD, width=2, fill="yellow2",
                         outline="black")
        panel.create_arc(260, 130, 360, 170, extent=180, start=268, style=CHORD, width=2, fill="yellow2",
                         outline="black")
        panel.create_arc(245, 200, 360, 165, extent=220, start=225, style=CHORD, width=2, fill="yellow2",
                         outline="black")
        panel.create_arc(255, 163, 295, 233, extent=215, start=178, style=CHORD, width=2, fill="yellow2",
                         outline="black")
        panel.create_arc(225, 155, 265, 245, extent=190, start=180, style=CHORD, width=2, fill="yellow2",
                         outline="black")
        panel.create_arc(170, 155, 215, 245, extent=190, start=170, style=CHORD, width=2, fill="yellow2",
                         outline="black")
        panel.create_arc(135, 158, 175, 233, extent=210, start=150, style=CHORD, width=2, fill="yellow2",
                         outline="black")
        panel.create_arc(80, 155, 192, 195, extent=198, start=105, style=CHORD, width=2, fill="yellow2",
                         outline="black")
        panel.create_arc(65, 120, 172, 160, extent=193, start=84, style=CHORD, width=2, fill="yellow2", outline="black")

        panel.create_arc(128, 50, 168, 133, extent=200, start=10, style=CHORD, width=2, fill="yellow2", outline="black")

        panel.create_arc(80, 83, 170, 123, extent=233, start=35, style=CHORD, width=2, fill="yellow2", outline="black")
        panel.create_arc(160, 40, 200, 125, extent=190, start=2, style=CHORD, width=2, fill="yellow2", outline="black")

        # tallo
        panel.create_polygon(210, 200, 210, 250, 220, 290, 235, 330, 230, 380, 230, 410,
                             245, 410, 245, 380, 250, 330, 235, 290, 225, 250, 225, 200, width=1, fill="forestgreen",
                             outline="black")
        # hoja derecha
        panel.create_arc(230, 250, 310, 300, extent=270, start=0, style=CHORD, width=2, fill="forestgreen",
                         outline="darkgreen")
        panel.create_arc(230, 265, 300, 295, extent=105, start=75, style=ARC, width=2, outline="darkgreen")
        # hoja izquierda
        panel.create_arc(125, 250, 215, 300, extent=270, start=270, style=CHORD, width=2, fill="forestgreen",
                         outline="darkgreen")
        panel.create_arc(130, 265, 215, 295, extent=105, start=0, style=ARC, width=2, outline="darkgreen")

        # fondo derecho
        panel.create_arc(245, 300, 360, 410, extent=180, start=0, style=CHORD, width=1, fill="darkgreen",
                         outline="black")
        panel.create_arc(245, 325, 380, 440, extent=170, start=0, style=CHORD, width=2, fill="forestgreen",
                         outline="darkgreen")
        panel.create_arc(240, 340, 365, 460, extent=105, start=35, style=ARC, width=2, fill="forestgreen",
                         outline="darkgreen")
        # fondo izquierdo
        panel.create_arc(115, 310, 235, 400, extent=195, start=345, style=CHORD, width=1, fill="darkgreen",
                         outline="black")
        panel.create_arc(105, 340, 235, 470, extent=170, start=20, style=CHORD, width=2, fill="forestgreen",
                         outline="darkgreen")
        panel.create_arc(135, 350, 240, 490, extent=130, style=ARC, start=8, width=2, fill="black", outline="darkgreen")
        # fondo medio
        panel.create_arc(185, 345, 350, 500, extent=180, start=0, style=CHORD, width=2, fill="forestgreen",
                         outline="darkgreen")
        panel.create_arc(185, 365, 315, 500, extent=130, style=ARC, start=40, width=2, outline="darkgreen")
    elif opc==4:
        panel = Canvas(vs,width=600, height=800, bg="linen")
        panel.pack()
        # cara
        panel.create_polygon(200, 300, 200, 450, 210, 470, 390, 470, 400, 450, 400, 300, width=2, fill="lemonchiffon",
                             outline="black")
        # cabeza
        panel.create_arc(100, 80, 500, 520, extent=180, start=0, style=CHORD, width=2, fill="gold", outline="black")
        # manchas

        panel.create_oval(290, 100, 380, 140, width=1, fill="goldenrod", outline="khaki")  # 1
        panel.create_oval(170, 110, 275, 190, width=1, fill="goldenrod", outline="khaki")  # 2
        panel.create_oval(130, 220, 180, 270, width=1, fill="goldenrod", outline="khaki")  # 3
        panel.create_oval(210, 200, 300, 290, width=1, fill="goldenrod", outline="khaki")  # 4
        panel.create_oval(320, 160, 350, 210, width=1, fill="goldenrod", outline="khaki")  # 5
        panel.create_oval(325, 235, 375, 275, width=1, fill="goldenrod", outline="khaki")  # 6
        panel.create_oval(390, 140, 465, 285, width=1, fill="goldenrod", outline="khaki")  # 7

        # ojos
        panel.create_oval(240, 320, 270, 390, width=1, fill="black", outline="black")
        panel.create_oval(330, 320, 360, 390, width=1, fill="black", outline="black")
        # pupila
        panel.create_oval(245, 325, 265, 355, width=1, fill="white", outline="black")
        panel.create_oval(335, 325, 355, 355, width=1, fill="white", outline="black")
        # boca
        panel.create_arc(260, 390, 340, 440, extent=180, style=ARC, start=180, width=2, fill="black", outline="black")
    elif opc==5:
        panel = Canvas(vs,width=1148, height=700, bg='light blue')
        panel.pack()
        # casa
        panel.create_rectangle(100, 410, 370, 650, width=2, fill='yellow', outline='black')
        # tejado
        panel.create_polygon(70, 409, 400, 409, 245, 200, width=2, fill='red', outline='black')
        # ventanas
        panel.create_rectangle(120, 420, 200, 500, width=2, fill='blue', outline='black')
        panel.create_rectangle(270, 420, 350, 500, width=2, fill='purple', outline='black')
        # Puerta
        panel.create_rectangle(200, 550, 260, 650, width=2, fill='red', outline='black')
        panel.create_line(230, 550, 230, 650, width=2, fill="black")
        panel.create_oval(215, 600, 200, 620, width=2, fill='brown', outline='black')
        # pasto
        panel.create_rectangle(1, 650, 1147, 700, width=2, fill='green', outline='black')
        # arbol
        panel.create_rectangle(600, 410, 570, 650, width=2, fill='brown', outline='black')
        panel.create_oval(700, 550, 480, 350, width=2, fill='green', outline='black')
        # sol
        panel.create_oval(1000, 150, 880, 50, width=2, fill='yellow', outline='black')
        panel.create_line(900, 200, 1000, 1, width=10, fill="yellow")
        panel.create_line(780, 125, 1100, 70, width=10, fill="yellow")
        panel.create_line(1050, 200, 880, 10, width=10, fill="yellow")
    elif opc==6:
        panel = Canvas(vs,width=200, height=200, bg="gray")
        panel.pack()

        # Primera parte negra
        panel.create_polygon(70, 50, 70, 60, 50, 60, 50, 70, 40, 70, 40, 150, 50, 150, 50, 160, 60, 160, 60, 170, 80,
                             170, 80, 180,
                             110, 180, 110, 170, 130, 170, 130, 160, 140, 160, 140, 150, 150, 150, 150, 70,
                             140, 70, 140, 60, 120, 60, 120, 50, 70, 50, width=1, fill="black")

        # ojo 1
        panel.create_polygon(50, 80, 50, 120, 60, 120, 60, 130, 80, 130, 80, 120, 90, 120, 90, 110, 80, 110, 80, 100,
                             70, 100, 70, 90
                             , 60, 90, 60, 80, 50, 80, width=1, fill="white")

        # ojo 2
        panel.create_polygon(140, 80, 130, 80, 130, 90, 120, 90, 120, 100, 110, 100, 110, 110, 100, 110, 100, 120, 110,
                             130, 130, 130, 130, 120
                             , 140, 120, 140, 80, 130, 80, width=1, fill="white")
    elif opc==7:
        panel = Canvas(vs,width=200, height=200, bg="yellow")
        panel.pack()
        # Parte negra
        panel.create_polygon(70, 10, 130, 10, 130, 20, 150, 20, 150, 30, 160, 30, 160, 50, 170, 50, 170, 60, 180, 60,
                             180, 130,
                             170, 130, 170, 140, 160, 140, 160, 160, 150, 160, 150, 170, 50, 170, 50, 160, 40, 160, 40,
                             140, 30, 140, 30, 130, 20, 130,
                             20, 60, 30, 60, 30, 50, 40, 50, 40, 30, 50, 30, 50, 20, 70, 20, 70, 10, width=1,
                             fill="black", outline="black")

        # Primera parte blanca
        panel.create_polygon(80, 20, 120, 20, 120, 30, 140, 30, 140, 40, 150, 40, 150, 60, 160, 60, 160, 70, 170, 70,
                             170, 120, 150, 120, 150, 110, 50, 110, 50, 120, 30, 120, 30, 70, 40, 70, 40, 60, 50, 60,
                             50, 40, 60, 40, 60, 30, 80, 30, 80, 20, width=1, fill="white", outline="white")

        # segunda parte blanca
        panel.create_polygon(60, 120, 140, 120, 140, 130, 150, 130, 150, 150, 140, 150, 140, 160, 60, 160, 60, 150,
                             50, 150, 50, 130, 60, 130, 60, 120, width=1, fill="white", outline="white")

        # ojos
        panel.create_rectangle(80, 120, 90, 140, width=1, fill="black", outline="black")
        panel.create_rectangle(110, 120, 120, 140, width=1, fill="black", outline="black")

        # manchas
        panel.create_polygon(80, 70, 120, 70, 120, 80, 130, 80, 130, 100, 120, 100, 120, 110, 80, 110, 80, 100, 70, 100,
                             70, 80, 80, 80, 80, 70, width=1, fill="red", outline="red")
        panel.create_polygon(110, 20, 120, 20, 120, 30, 140, 30, 140, 50, 120, 50, 120, 40, 110, 40, 110, 20, width=1,
                             fill="red", outline="red")
        panel.create_polygon(80, 20, 90, 20, 90, 40, 80, 40, 80, 50, 60, 50, 60, 30, 80, 30, 80, 20, width=1,
                             fill="red", outline="red")
        panel.create_polygon(40, 60, 60, 60, 60, 90, 50, 90, 50, 100, 30, 100, 30, 70, 40, 70, 40, 60, width=1,
                             fill="red", outline="red")
        panel.create_polygon(140, 60, 160, 60, 160, 70, 170, 70, 170, 100, 150, 100, 150, 90, 140, 90, 140, 60, width=1,
                             fill="red", outline="red")

def main():
    vp=Tk()
    vp.geometry("400x600+50+50")
    vp.configure(bg="gray")
    vp.title("Antologia de Programas")
    bt1=Button(vp,text="Perrito by Ambrocio Laureano",bg="teal",fg="White",command=lambda:eleccion(1,"Program by Ambrocio Laureano"))
    bt1.pack(padx=5, pady=5,fill=X)
    bt2 = Button(vp, text="Angry Bird by Griselda Maldonado", bg="teal", fg="White", command=lambda: eleccion(2, "Program by Griselda Maldonado"))
    bt2.pack(padx=5, pady=5, fill=X)
    bt3 = Button(vp, text="Girasol by Griselda Maldonado", bg="teal", fg="White",command=lambda: eleccion(3, "Program by Griselda Maldonado"))
    bt3.pack(padx=5, pady=5, fill=X)
    bt4 = Button(vp, text="Hongo by Griselda Maldonado", bg="teal", fg="White", command=lambda: eleccion(4, "Program by Griselda Maldonado"))
    bt4.pack(padx=5, pady=5, fill=X)
    bt5 = Button(vp, text="Paisaje by Manuel Ramirez", bg="teal", fg="White", command=lambda: eleccion(5, "Program by Manuel Ramirez"))
    bt5.pack(padx=5, pady=5, fill=X)
    bt6 = Button(vp, text="Venom by Livan Alejandro", bg="teal", fg="White", command=lambda: eleccion(6, "Program by Livan Alejandro"))
    bt6.pack(padx=5, pady=5, fill=X)
    bt6 = Button(vp, text="Seta by Carolina Sauceda", bg="teal", fg="White", command=lambda: eleccion(7, "Program by Carolina Sauceda"))
    bt6.pack(padx=5, pady=5, fill=X)

    vp.mainloop()


main()

Salida:

Si deseas obtener el codigo fuente descarga aqui o si falla ese link consulta aqui

Si deseas obtener la plantilla del codigo para una interfaz similar descarga aqui o si falla ese link consulta aqui

Comentarios