Ejercicios de distintas figuras en diferentes ventanas, con botones, funciones etc..
from tkinter import *
VentanaP = Tk()
Hija1 = Toplevel(VentanaP)
Hija2 = Toplevel(VentanaP)
Hija3 = Toplevel(VentanaP)
Hija4 = Toplevel(VentanaP)
Hija5 = Toplevel(VentanaP)
Hija6 = Toplevel(VentanaP)
VentanaP.title("Figuras")
Hija1.title("Circulo")
Hija2.title("Rectangulo")
Hija3.title("Lineas")
Hija4.title("Quesito")
Hija5.title("Arco")
Hija6.title("Grafico")
Hija1.protocol("WM_DELETE_WINDOW", "onexit")
Hija2.protocol("WM_DELETE_WINDOW", "onexit")
Hija3.protocol("WM_DELETE_WINDOW", "onexit")
Hija4.protocol("WM_DELETE_WINDOW", "onexit")
Hija5.protocol("WM_DELETE_WINDOW", "onexit")
Hija6.protocol("WM_DELETE_WINDOW", "onexit")
def mostrar(ventana): ventana.deiconify()
def ocultar(ventana): ventana.withdraw()
def ejecutar(f): VentanaP.after(200, f)
VentanaP.config(bg="blue")
VentanaP.geometry("468x300")
def circulo(ventana):
Hija1.deiconify()
circulo = Canvas(Hija1, width=210, height=210, bg="white")
circulo.pack()
cuadro = circulo.create_oval(10, 10, 200, 200, width=3, fill="blue")
def rectangulo(ventana):
Hija2.deiconify()
rectangulo = Canvas(Hija2, width=210, height=210, bg="white")
rectangulo.pack(expand=YES, fill=BOTH)
rectangulo.create_rectangle(10, 10, 200, 200, width=3, fill='black')
def lineas(ventana):
Hija3.deiconify()
linea = Canvas(Hija3, width=210, height=210, bg='white')
linea.pack(expand=YES, fill=BOTH)
linea.create_line(0, 200, 200, 0, width=10, fill='black', dash=(4, 4))
linea.create_line(0, 0, 200, 200, width=10, fill='black', dash=(4, 4))
def quesito(ventana):
Hija4.deiconify()
quesito = Canvas(Hija4,width=300, height=200, bg='white')
quesito.pack(expand=YES, fill=BOTH)
quesito.create_arc(10, 10, 190, 190, start=270, extent=90, fill='gray90')
def arco(ventana):
Hija5.deiconify()
arco = Canvas(Hija5, width=300, height=200, bg='white')
arco.pack(expand=YES, fill=BOTH)
xy = 10, 10, 190, 190 arco.create_arc(xy, start=0, extent=270, fill='gray60')
def grafico(ventana):
Hija6.deiconify()
arco = Canvas(Hija6, width=300, height=200, bg='white')
arco.pack(expand=YES, fill=BOTH)
xy = 10, 10, 190, 190 arco.create_arc(xy, start=0, extent=270, fill='gray60')
arco.create_arc(10, 10, 190, 190, start=270, extent=90, fill='gray90')
boton2 = Button(Hija6, text="Cerrar", relief=SOLID, bg='green', cursor="box_spiral", command=lambda: ejecutar(ocultar(Hija6)))
boton2.pack()
boton6 = Button(Hija4, text="Cerrar", relief=SOLID, bg='green', cursor="box_spiral", command=lambda: ejecutar(ocultar(Hija4)))
boton6.pack()
boton4 = Button(Hija5, text="Cerrar", relief=SOLID, bg='green', cursor="box_spiral", command=lambda: ejecutar(ocultar(Hija5)))
boton4.pack()
boton3 = Button(Hija1, text="Cerrar", relief=SOLID, bg='green', cursor="umbrella", command=lambda: ejecutar(ocultar(Hija1)))
boton3.pack()
boton5 = Button(Hija2, text="Cerrar", relief=SOLID, bg='red', cursor="pencil", command=lambda: ejecutar(ocultar(Hija2)))
boton5.pack()
boton2 = Button(Hija3, text="Cerrar", relief=SOLID, bg='blue', cursor="umbrella", command=lambda: ejecutar(ocultar(Hija3)), fg='#ffffff')
boton2.pack()
b1 = Button(VentanaP, text="Mostrar circulo", relief=FLAT, bg='white', cursor="sizing", command=lambda: ejecutar(circulo(Hija1)))
b1.grid(row=1, column=3)
b2 = Button(VentanaP, text="Mostrar rectangulo", relief=FLAT, bg='black', cursor="hand1", command=lambda: ejecutar(rectangulo(VentanaP)), fg='#ffffff')
b2.grid(row=1, column=2)
b3 = Button(VentanaP, text="Mostrar lineas", relief=FLAT, bg='white', cursor="hand2", command=lambda: ejecutar(lineas(VentanaP)))
b3.grid(row=1, column=1)
b4 = Button(VentanaP, text="Mostrar Quesito", relief=FLAT, bg='white', cursor="hand2", command=lambda: ejecutar(quesito(VentanaP)))
b4.grid(row=1, column=4)
b5 = Button(VentanaP, text="Mostrar Arco", relief=FLAT, bg='white', cursor="hand2", command=lambda: ejecutar(arco(VentanaP)))
b5.grid(row=1, column=5)
b6 = Button(VentanaP, text="Mostrar Grafico", relief=FLAT, bg='white', cursor="hand2", command=lambda: ejecutar(grafico(VentanaP)))
b6.grid(row=2, column=1)
Hija3.withdraw()
Hija2.withdraw()
Hija1.withdraw()
Hija4.withdraw()
Hija5.withdraw()
Hija6.withdraw()
VentanaP.mainloop()
No hay comentarios:
Publicar un comentario