Figuras:
En esta practica jugamos con la función poligono del canvas y creamos una figura apartir de dicha función en mi caso agregre dos mas una estrella y una trifuerza (es de un vidiojuego que me gusta mucho :v)Código:
from Tkinter import *
v0 = Tk()
v1=Toplevel(v0)
v2=Toplevel(v0)
v3=Toplevel(v0)
v4=Toplevel(v0)
v5=Toplevel(v0)
v6=Toplevel(v0)
v7=Toplevel(v0)
v8=Toplevel(v0)
v9=Toplevel(v0)
v10=Toplevel(v0)
v0.title("Figuras")
v1.title("Circulo")
v2.title("Rectangulo")
v3.title("Lineas")
v4.title("Arco")
v5.title("Quesito")
v6.title("Partes de quesito")
v7.title("Texto")
v8.title("Poligono")
v9.title("Estrella")
v10.title("Trifuerza")
v1.protocol("WM_DELETE_WINDOW", "onexit")
v2.protocol("WM_DELETE_WINDOW", "onexit")
v3.protocol("WM_DELETE_WINDOW", "onexit")
v4.protocol("WM_DELETE_WINDOW", "onexit")
v5.protocol("WM_DELETE_WINDOW", "onexit")
v6.protocol("WM_DELETE_WINDOW", "onexit")
v7.protocol("WM_DELETE_WINDOW", "onexit")
v8.protocol("WM_DELETE_WINDOW", "onexit")
v9.protocol("WM_DELETE_WINDOW", "onexit")
v10.protocol("WM_DELETE_WINDOW", "onexit")
def mostrar(ventana): ventana.deiconify()
def ocultar(ventana):ventana.withdraw()
def ejecutar(f): v0.after(200,f)
v0.config(bg="blue")
v0.geometry("564x150")
def circulo(ventana):
v1.deiconify()
circulo = Canvas(v1,width=210, height=210, bg="white")
circulo.pack()
cuadro = circulo.create_oval(10, 10, 200, 200, width=3,fill="blue")
def rectangulo(ventana):
v2.deiconify()
rectangulo = Canvas(v2,width=210, height=210, bg="black")
rectangulo.pack(expand=YES, fill=BOTH)
rectangulo.create_rectangle(10, 10, 200, 200, width=3, fill='white')
def lineas(ventana):
v3.deiconify()
linea = Canvas(v3,width=210, height=210, bg='#0024FF')
linea.pack(expand=YES, fill=BOTH)
linea.create_line(0, 200, 200, 0, width=10, fill='white', dash=(4, 4))
linea.create_line(0, 0, 200, 200, width=10, fill='white',dash=(4, 4))
def arc(ventana):
v4.deiconify()
arco = Canvas(v4,width=210, height=210, bg='blue')
arco.pack(expand=YES, fill=BOTH)
xy = 10, 10, 190, 190
arco.create_arc(xy, start=0, extent=180, fill='#EC6F0A')
def ques(ventana):
v5.deiconify()
quesi = Canvas(v5,width=210, height=210, bg='#00FF18')
quesi.pack(expand=YES, fill=BOTH)
quesi.create_arc(10, 10, 190, 190, start=270, extent=90, fill='yellow')
def quepar(ventana):
v6.deiconify()
par1= Canvas(v6, width=210, height=210, bg='#E0ECFF')
par1.pack()
par1.create_arc(10, 10, 190, 190, start=0, extent=90, fill='yellow')
par1.create_arc(10, 10, 190, 190, start=90, extent=90, fill='yellow')
par1.create_arc(10, 10, 190, 190, start=180, extent=90, fill='yellow')
par1.create_arc(10, 10, 190, 190, start=270, extent=90, fill='yellow')
def cretex(ventana):
v7.deiconify()
te=Canvas(v7, width=210, height=210)
te.pack()
te.create_text(115,70,fill="darkblue",font="bold",text="Holi :v")
def crepoli(ventana):
v8.deiconify()
po=Canvas(v8,width=210, height=210,bg='#6600FF')
po.pack()
po.create_polygon(40, 40, 40, 140, 140, 140, 140, 100, fill="lightblue", outline="blue", width=2,dash=10)
def creest(ventana):
v9.deiconify()
po=Canvas(v9,width=385, height=290,bg='white')
po.pack()
po.create_polygon(200, 10,380, 280,10, 100,380, 100,10, 280,fill='',outline='blue',dash=(5))
def trifuerza(ventana):
v10.deiconify()
po=Canvas(v10,width=385, height=290)
po.pack()
p1=Canvas(v10,width=180, height=150)
p1.place(x=102,y=30)
p1.create_polygon(100, 10, 10, 140, 140, 140, 180, 140, fill="#FCFF00", outline="#FFF715", width=6)
p2=Canvas(v10,width=180, height=150)
p2.place(x=185,y=170)
p2.create_polygon(100, 5, 10, 140, 140, 140, 180, 140, fill="#FCFF00", outline="#FFF715", width=6)
p3=Canvas(v10,width=180, height=150)
p3.place(x=8,y=170)
p3.create_polygon(100, 5, 10, 140, 140, 140, 180, 140, fill="#FCFF00", outline="#FFF715", width=6)
boton1= Button(v1, text="Cerrar",relief=SOLID,bg='green',cursor="box_spiral", command=lambda: ejecutar(ocultar(v1)))
boton1.pack()
boton2= Button(v2, text="Cerrar",relief=SOLID,bg='red',cursor="pencil", command=lambda: ejecutar(ocultar(v2)))
boton2.pack()
boton3= Button(v3, text="Cerrar",relief=SOLID,bg='blue',cursor="umbrella", command=lambda: ejecutar(ocultar(v3)),fg='#ffffff')
boton3.pack()
boton4= Button(v4, text="Cerrar",relief=SOLID,bg='black',cursor="rtl_logo", command=lambda: ejecutar(ocultar(v4)),fg='#ffffff')
boton4.pack()
boton5= Button(v5, text="Cerrar",relief=SOLID,bg='yellow',cursor="sailboat", command=lambda: ejecutar(ocultar(v5)))
boton5.pack()
boton6= Button(v6, text="Cerrar",relief=SOLID,bg='#FF6C00',cursor="spraycan", command=lambda: ejecutar(ocultar(v6)))
boton6.pack()
boton7= Button(v7, text="Cerrar",relief=SOLID,bg='#00FF18',cursor="top_right_corner", command=lambda: ejecutar(ocultar(v7)))
boton7.pack()
boton8= Button(v8, text="Cerrar",relief=SOLID,bg='#8A00FF',cursor="crosshair", command=lambda: ejecutar(ocultar(v8)),fg='#ffffff')
boton8.pack()
boton9= Button(v9, text="Cerrar",relief=SOLID,bg='#00F6FF',cursor="star", command=lambda: ejecutar(ocultar(v9)))
boton9.pack()
boton10= Button(v10, text="Cerrar",relief=SOLID,bg='blue',cursor="watch", command=lambda: ejecutar(ocultar(v10)),fg='#ffffff')
boton10.pack()
b1=Button(v0,text="Circulo",relief=FLAT,bg='white',cursor="sizing",command=lambda: ejecutar(circulo(v1)))
b1.grid(row=1,column=1)
b2=Button(v0,text="Rectangulo",relief=FLAT,bg='black',cursor="hand1",command=lambda: ejecutar(rectangulo(v0)),fg='#ffffff')
b2.grid(row=1,column=2)
b3=Button(v0,text="Lineas",relief=FLAT,bg='white',cursor="hand2",command=lambda: ejecutar(lineas(v0)))
b3.grid(row=1,column=3)
b4=Button(v0,text="Arco",relief=FLAT,bg='black',cursor="bogosity",command=lambda: ejecutar(arc(v0)),fg='#ffffff')
b4.grid(row=1,column=4)
b5=Button(v0,text="Quesito",relief=FLAT,bg='white',cursor="bottom_right_corner",command=lambda: ejecutar(ques(v0)))
b5.grid(row=1,column=5)
b5=Button(v0,text="Quesito por partes",relief=FLAT,bg='black',cursor="draft_large",command=lambda: ejecutar(quepar(v0)),fg='#ffffff')
b5.grid(row=1,column=6)
b6=Button(v0,text="Texto",relief=FLAT,bg='white',cursor="exchange",command=lambda: ejecutar(cretex(v0)))
b6.grid(row=1,column=7)
b6=Button(v0,text="Poligono",relief=FLAT,bg='black',cursor="iron_cross",command=lambda: ejecutar(crepoli(v0)),fg='#ffffff')
b6.grid(row=1,column=8)
b6=Button(v0,text="Estrella",relief=FLAT,bg='white',cursor="plus",command=lambda: ejecutar(creest(v0)))
b6.grid(row=1,column=9)
b7=Button(v0,text="Trifuerza",relief=FLAT,bg='black',cursor="heart",command=lambda: ejecutar(trifuerza(v0)),fg='#ffffff')
b7.grid(row=1,column=10)
mens=Label(v0, text="Holi :v",bg="blue",fg="white").place(x=282,y=80)
v10.withdraw()
v9.withdraw()
v8.withdraw()
v7.withdraw()
v6.withdraw()
v5.withdraw()
v4.withdraw()
v3.withdraw()
v2.withdraw()
v1.withdraw()
v0.mainloop()
Codigo de mega-trifuerza:
def megatrifuerza(ventana):
v1.deiconify()
po=Canvas(v1,width=1000, height=550)
po.pack()
p1=Canvas(v1,width=92, height=61)
p1.place(x=446,y=30)
p1.create_polygon(52, 4, 10, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p2=Canvas(v1,width=92, height=61)
p2.place(x=488,y=93)
p2.create_polygon(52, 4, 10, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p3=Canvas(v1,width=92, height=61)
p3.place(x=400,y=93)
p3.create_polygon(52, 4, 10, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p4=Canvas(v1,width=92, height=61)
p4.place(x=352,y=156)
p4.create_polygon(52, 4, 5, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p5=Canvas(v1,width=92, height=61)
p5.place(x=300,y=220)
p5.create_polygon(52, 4, 10, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p6=Canvas(v1,width=92, height=61)
p6.place(x=396,y=220)
p6.create_polygon(52, 4, 5, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p7=Canvas(v1,width=92, height=61)
p7.place(x=532,y=156)
p7.create_polygon(50, 4, 10, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p8=Canvas(v1,width=92, height=61)
p8.place(x=488,y=220)
p8.create_polygon(50, 4, 7, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p9=Canvas(v1,width=92, height=61)
p9.place(x=578,y=220)
p9.create_polygon(50, 4, 7, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p10=Canvas(v1,width=92, height=61)
p10.place(x=620,y=285) #abajo
p10.create_polygon(52, 4, 10, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p11=Canvas(v1,width=92, height=61)
p11.place(x=664,y=350)
p11.create_polygon(52, 4, 10, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p12=Canvas(v1,width=92, height=61)
p12.place(x=572,y=350)
p12.create_polygon(52, 4, 10, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p13=Canvas(v1,width=92, height=61)
p13.place(x=524,y=414)
p13.create_polygon(52, 4, 5, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p14=Canvas(v1,width=92, height=61)
p14.place(x=472,y=478)
p14.create_polygon(52, 4, 10, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p15=Canvas(v1,width=92, height=61)
p15.place(x=566,y=478)
p15.create_polygon(52, 4, 5, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p16=Canvas(v1,width=92, height=61)
p16.place(x=708,y=414)
p16.create_polygon(50, 4, 10, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p17=Canvas(v1,width=92, height=61)
p17.place(x=754,y=478)
p17.create_polygon(50, 4, 7, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p18=Canvas(v1,width=92, height=61)
p18.place(x=662,y=478)
p18.create_polygon(50, 4, 7, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p10=Canvas(v1,width=92, height=61)
p10.place(x=252,y=285) #abajo
p10.create_polygon(52, 4, 10, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p11=Canvas(v1,width=92, height=61)
p11.place(x=204,y=350)
p11.create_polygon(52, 4, 10, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p12=Canvas(v1,width=92, height=61)
p12.place(x=296,y=350)
p12.create_polygon(52, 4, 10, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p13=Canvas(v1,width=92, height=61)
p13.place(x=158,y=414)
p13.create_polygon(52, 4, 5, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p14=Canvas(v1,width=92, height=61)
p14.place(x=106,y=478)
p14.create_polygon(52, 4, 10, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p15=Canvas(v1,width=92, height=61)
p15.place(x=200,y=478)
p15.create_polygon(52, 4, 5, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p16=Canvas(v1,width=92, height=61)
p16.place(x=340,y=414)
p16.create_polygon(50, 4, 10, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p17=Canvas(v1,width=92, height=61)
p17.place(x=293,y=478)
p17.create_polygon(50, 4, 7, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
p18=Canvas(v1,width=92, height=61)
p18.place(x=383,y=478)
p18.create_polygon(50, 4, 7, 60, 60, 60, 90, 60, fill="#FCFF00", outline="#FFF715", width=6)
Comentarios
Publicar un comentario