- Ejercicio de Figuras en ventanas hijas con PyCharm -
#1. CÍRCULO
def circulo(ven):
ventanah3.deiconify()
circulo = Canvas(ventanah3, width=210, height=210, bg="black")
circulo.pack(expand=YES, fill=BOTH)
circulo.create_oval(10, 10, 200, 200, width=3, fill='blue')
#2 CUADRADO.
Código
def rectangulo(ven):
ventanah1.deiconify()
rectangulo = Canvas(ventanah1,width=210, height=210, bg="black")
rectangulo.pack(expand=YES, fill=BOTH)
rectangulo.create_rectangle(10, 10, 200, 200, width=3, fill='indigo')
#3 LÍNEA EN DIAGONAL
Código
def linea(ven):
ventanah2.deiconify()
linea = Canvas(ventanah2,width=210, height=210, bg="black")
linea.pack(expand=YES, fill=BOTH)
linea.create_line(5, 5, 200, 200, width=10, fill='lime')
#4 QUESITO
Código
def quesito(ven):
ventanah4.deiconify()
quesito = Canvas(ventanah4, width=210, height=210, bg='black')
quesito.pack(expand=YES, fill=BOTH)
quesito.create_arc(10, 10, 190, 190, start=270, extent=90, fill='dark red')
#5 PAY
Código
def pay(ven):
ventanah5.deiconify()
pay = Canvas(ventanah5, width=210, height=200, bg='black')
pay.pack(expand=YES, fill=BOTH)
xy = 10, 10, 190, 190
pay.create_arc(xy, start=0, extent=270, fill='magenta')
#6 TEXTO
Código
canvas = Canvas(ven,width=300, height=300, bg='black')
canvas.pack(expand=YES, fill=BOTH)
widget = Label(canvas, text='AAA', fg='hot pink', bg='black')
widget.pack()
ven.deiconify()
#7 POLÍGONO
Código
canvas = Canvas(ven, width=210, height=200, bg='black')
canvas.pack(expand=YES, fill=BOTH)
canvas.create_polygon(40, 40, 40, 140, 140, 140, 140, 100, fill="dark orange", outline="dark orange", width=6)
ven.deiconify()
#8 ESTRELLA
Código
def star(ven):
canvas = Canvas(ven, width=200, height=200, bg='black')
canvas.pack(expand=YES, fill=BOTH)
puntos = [100, 140, 110, 110, 140, 100, 110, 90, 100, 60, 90, 90, 60, 100, 90, 110]
canvas.create_polygon(puntos, fill="teal", outline="teal", width=6)
ven.deiconify()
#9 WONEJO
def wonejo(ven):
canvas = Canvas(ven, width=390, height=350, bg='black')
canvas.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]
canvas.create_polygon(puntos, fill="white", outline="white", width=9)
ven.deiconify()
CÓDIGO GENERAL
from Tkinter import *ventanap = Tk()
ventanap.config(bg="black")
ventanap.geometry("700x90")
ventanap.title("Figuritas Kawaii")
ventanah1 = Toplevel(ventanap)
ventanah1.protocol("WM_DELETE_WINDOW", "onexit")
ventanah2 = Toplevel(ventanap)
ventanah2.protocol("WM_DELETE_WINDOW", "onexit")
ventanah3 = Toplevel(ventanap)
ventanah3.protocol("WM_DELETE_WINDOW", "onexit")
ventanah4 = Toplevel(ventanap)
ventanah4.protocol("WM_DELETE_WINDOW", "onexit")
ventanah5 = Toplevel(ventanap)
ventanah5.protocol("WM_DELETE_WINDOW", "onexit")
ventanah6 = Toplevel(ventanap)
ventanah6.protocol("WM_DELETE_WINDOW", "onexit")
ventanah7 = Toplevel(ventanap)
ventanah7.protocol("WM_DELETE_WINDOW", "onexit")
ventanah8 = Toplevel(ventanap)
ventanah8.protocol("WM_DELETE_WINDOW", "onexit")
ventanah9 = Toplevel(ventanap)
ventanah9.protocol("WM_DELETE_WINDOW", "onexit")
def ejecutar(v,f):
v.after(200, f)
def mostrar(ventana):
ventana.deiconify()
def ocultar(ventana):
ventana.withdraw()
def rectangulo(ven):
rectangulo = Canvas(ven,width=210, height=210, bg="black")
rectangulo.pack(expand=YES, fill=BOTH)
rectangulo.create_rectangle(10, 10, 200, 200, width=3, fill='indigo')
ven.deiconify()
def linea(ven):
linea = Canvas(ven,width=210, height=210, bg="black")
linea.pack(expand=YES, fill=BOTH)
linea.create_line(5, 5, 200, 200, width=10, fill='lime')
ven.deiconify()
def circulo(ven):
circulo = Canvas(ven, width=210, height=210, bg="black")
circulo.pack(expand=YES, fill=BOTH)
circulo.create_oval(10, 10, 200, 200, width=3, fill='blue')
ven.deiconify()
def quesito(ven):
canvas = Canvas(ven, width=210, height=210, bg='black')
canvas.pack(expand=YES, fill=BOTH)
canvas.create_arc(10, 10, 190, 190, start=270, extent=90, fill='dark red')
ven.deiconify()
def pay(ven):
canvas = Canvas(ven, width=210, height=200, bg='black')
canvas.pack(expand=YES, fill=BOTH)
xy = 10, 10, 190, 190
canvas.create_arc(xy, start=0, extent=270, fill='magenta')
ven.deiconify()
def texto(ven):
canvas = Canvas(ven,width=300, height=300, bg='black')
canvas.pack(expand=YES, fill=BOTH)
widget = Label(canvas, text='AAA', fg='hot pink', bg='black')
widget.pack()
ven.deiconify()
def poly(ven):
canvas = Canvas(ven, width=210, height=200, bg='black')
canvas.pack(expand=YES, fill=BOTH)
canvas.create_polygon(40, 40, 40, 140, 140, 140, 140, 100, fill="dark orange", outline="dark orange"
, width=6)
ven.deiconify()
def star(ven):
canvas = Canvas(ven, width=210, height=200, bg='black')
canvas.pack(expand=YES, fill=BOTH)
puntos = [100, 140, 110, 110, 140, 100, 110, 90, 100, 60, 90, 90, 60, 100, 90, 110]
canvas.create_polygon(puntos, fill="teal", outline="teal", width=6)
ven.deiconify()
def wonejo(ven):
canvas = Canvas(ven, width=390, height=350, bg='black')
canvas.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]
canvas.create_polygon(puntos, fill="white", outline="white", width=9)
ven.deiconify()
boton1= Button(ventanah1, text="Exit", command=lambda: ejecutar(ventanah1,ocultar(ventanah1)))
boton1.pack()
boton2= Button(ventanah2, text="Exit", command=lambda: ejecutar(ventanah2,ocultar(ventanah2)))
boton2.pack()
boton3= Button(ventanah3, text="Exit", command=lambda: ejecutar(ventanah3,ocultar(ventanah3)))
boton3.pack()
boton4= Button(ventanah4, text="Exit", command=lambda: ejecutar(ventanah4,ocultar(ventanah4)))
boton4.pack()
boton5= Button(ventanah5, text="Exit", command=lambda: ejecutar(ventanah5,ocultar(ventanah5)))
boton5.pack()
boton6= Button(ventanah6, text="Exit", command=lambda: ejecutar(ventanah6,ocultar(ventanah6)))
boton6.pack()
boton7= Button(ventanah7, text="Exit", command=lambda: ejecutar(ventanah7,ocultar(ventanah7)))
boton7.pack()
boton8= Button(ventanah8, text="Exit", command=lambda: ejecutar(ventanah8,ocultar(ventanah8)))
boton8.pack()
boton9= Button(ventanah9, text="Exit", command=lambda: ejecutar(ventanah9,ocultar(ventanah9)))
boton9.pack()
botoncir = Button(ventanap, text="Push Circulo",command=lambda: ejecutar (ventanah1,circulo(ventanah1)))
botoncir.grid(row=1, column=1)
botonrec = Button(ventanap, text="Push Rectangulo",command=lambda: ejecutar (ventanah2,rectangulo(ventanah2)))
botonrec.grid(row=1, column=2)
botonlin = Button(ventanap, text="Push Linea",command=lambda: ejecutar (ventanah3,linea(ventanah3)))
botonlin.grid(row=1, column=3)
botonques = Button(ventanap, text="Push Quesito",command=lambda: ejecutar (ventanah4,quesito(ventanah4)))
botonques.grid(row=1, column=4)
botonpay = Button(ventanap, text="Push Pay",command=lambda: ejecutar (ventanah5,pay(ventanah5)))
botonpay.grid(row=1, column=5)
botontex = Button(ventanap, text="Push Texto",command=lambda: ejecutar (ventanah6,texto(ventanah6)))
botontex.grid(row=1, column=6)
botonpoly = Button(ventanap, text="Push Poligono",command=lambda: ejecutar (ventanah7,poly(ventanah7)))
botonpoly.grid(row=1, column=7)
botonstar = Button(ventanap, text="Push Estrella",command=lambda: ejecutar (ventanah8,star(ventanah8)))
botonstar.grid(row=1, column=8)
botonwonejo = Button(ventanap, text="Push Wonejo",command=lambda: ejecutar (ventanah9,wonejo(ventanah9)))
botonwonejo.grid(row=1, column=9)
ventanah1.withdraw()
ventanah2.withdraw()
ventanah3.withdraw()
ventanah4.withdraw()
ventanah5.withdraw()
ventanah6.withdraw()
ventanah7.withdraw()
ventanah8.withdraw()
ventanah9.withdraw()
ventanap.mainloop()
Comentarios
Publicar un comentario