from Tkinter import *
def mostrar(num):
v1=Toplevel(v0)
v1.title('Ventana hija')
v1.protocol('WM_DELETE_WINDOW','onexit')
v1.config(bg='blue')
v1.geometry('800x500')
if num == 1:
hola = Canvas(v1,width=300,height=210,bg='green')
hola.pack(expand=YES,fill=BOTH)
hola.create_oval(10,10,200,200, width=5,fill='blue')
b1 = Button(hola, text='Ocultar', command=lambda: ejecutar(Ocultar(v1)))
b1.grid(row=1,column=3)
if num == 2:
hola = Canvas(v1, width=300, height=300, bg='white')
hola.pack(expand=YES, fill=BOTH)
hola.create_rectangle(70,70,200,200, width=5,fill="red")
b2 = Button(hola, text='Ocultar', command=lambda: ejecutar(Ocultar(v1)))
b2.grid(row=1, column=3)
if num == 3:
hola = Canvas(v1, width=300, height=300, bg='white')
hola.pack(expand=YES, fill=BOTH)
hola.create_line(70,70,200, 200, width=5, fill="red")
b3 = Button(hola, text='Ocultar', command=lambda: ejecutar(Ocultar(v1)))
b3.grid(row=1, column=3)
if num == 4:
hola = Canvas(v1, width=300, height=300, bg='black')
hola.pack(expand=YES, fill=BOTH)
hola.create_line(70, 70, 200, 200, width=5, fill="red")
hola.create_line(200, 70, 70, 200, width=5, fill="gray")
b4 = Button(hola, text='Ocultar', command=lambda: ejecutar(Ocultar(v1)))
b4.grid(row=1, column=3)
if num == 5:
hola = Canvas(v1, width=300, height=300, bg='white')
hola.pack(expand=YES, fill=BOTH)
hola.create_polygon(200, 15, 380, 280, 15, 100, 380, 100, 10, 280, width=5, fill="red")
b5 = Button(hola, text='Ocultar', command=lambda: ejecutar(Ocultar(v1)))
b5.grid(row=1, column=3)
if num == 6:
hola = Canvas(v1, width=800, height=800, bg='white')
hola.pack(expand=YES, fill=BOTH)
hola.create_polygon(300, 300, 400, 200, 500, 200, 600, 300, 700, 200, 800, 200, 900, 300, 878, 395, 600, 700,
325, 401, fill="red", outline="brown", width=6)
b6 = Button(hola, text='Ocultar', command=lambda: ejecutar(Ocultar(v1)))
b6.grid(row=1, column=3)
def Ocultar(ventana):
ventana.destroy()
def ejecutar(f):
v0.after(200,f)
v0= Tk() #Este es mi objeto ventana
v0.title('Ventana Madre')
v0.config(bg='white')
v0.geometry('500x500')
b1=Button(v0, text='Abrir ventana con circulo',command=lambda: ejecutar(mostrar(1)))
b1.grid(row=1,column=10)
b2=Button(v0, text='Abrir ventana con cuadro',command=lambda: ejecutar(mostrar(2)))
b2.grid(row=4,column=10)
b3=Button(v0, text='Hacer linea',command=lambda: ejecutar(mostrar(3)))
b3.grid(row=6,column=10)
b4=Button(v0, text='Hacer cruz',command=lambda: ejecutar(mostrar(4)))
b4.grid(row=8,column=10)
b5=Button(v0, text='Hacer poligono',command=lambda: ejecutar(mostrar(5)))
b5.grid(row=10,column=10)
b6=Button(v0, text='Hacer corazon',command=lambda: ejecutar(mostrar(6)))
b6.grid(row=12,column=10)
v0=mainloop()
martes, 19 de marzo de 2019
Figura propia de corazón en Python.
En este programa se realizo una figura de un corazón hecha por mi mismo, haciendo uso de la librería Tkinter.