programa 1 figuras con ventana hija
codigo
# -*-
coding: utf-8 -*-from tkinter import *
from
Tkinter import*
ventanap =
Tk()
ventanap.config(bg="blue")
ventanap.geometry("500x500")
ventanap.title("Hacer
rectangulo")
ventanah =
Toplevel(ventanap)
ventanah.protocol("WM_DELETE_WINDOW",
"onexit")
def ejecutar(f):
ventanah.after(200,
f)
def mostrar(ventana):
ventana.deiconify()
def rectangulo(ven):
ventanah.deiconify()
rectangulo = Canvas(ventanah,width=210,
height=210, bg="yellow")
rectangulo.pack(expand=YES, fill=BOTH)
rectangulo.create_rectangle(10, 10, 200,
200, width=3, fill='orange')
def
linea(ven):
ventanah.deiconify()
linea = Canvas(ventanah,width=210,
height=210, bg="white")
linea.pack(expand=YES, fill=BOTH)
linea.create_line(5, 5, 200, 200, width=3,
fill='black')
def
ocultar(ventana):
ventanah.withdraw()
def
circulo(ven):
ventanah.deiconify()
circulo = Canvas(ventanah,width=210,
height=210, bg="red")
circulo.pack(expand=YES, fill=BOTH)
circulo.create_oval(10, 10, 200, 200,
width=3, fill='blue')
boton2=
Button(ventanah, text="Cerrar", command=lambda:
ejecutar(ocultar(ventanah)))
boton2.pack()
botoncir =
Button(ventanap, text="ver circulo",command=lambda: ejecutar
(circulo(ventanap)))
botoncir.grid(row=1,
column=1)
botonrec =
Button(ventanap, text="ver rectangulo",command=lambda: ejecutar
(rectangulo(ventanap)))
botonrec.grid(row=1,
column=2)
botonlin =
Button(ventanap, text="ver linea",command=lambda: ejecutar
(linea(ventanap)))
botonlin.grid(row=1,
column=3)
ventanah.withdraw()
ventanap.mainloop()
codigo
from
Tkinter import *
v0 = Tk()
v1 =
Toplevel(v0)
v2 =
Toplevel(v0)
v3 =
Toplevel(v0)
v0.title("Figuras")
v1.title("Circulo")
v2.title("Rectangulo")
v3.title("Lineas")
v1.protocol("WM_DELETE_WINDOW",
"onexit")
v2.protocol("WM_DELETE_WINDOW",
"onexit")
v3.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("288x300")
def circulo(ventana):
v1.deiconify()
circulo = Canvas(v1, width=210, height=210,
bg="blue")
circulo.pack()
cuadro = circulo.create_oval(10, 10, 200,
200, width=3, fill="red")
def rectangulo(ventana):
v2.deiconify()
rectangulo = Canvas(v2, width=210, height=210,
bg="white")
rectangulo.pack(expand=YES, fill=BOTH)
rectangulo.create_rectangle(10, 10, 200,
200, width=3, fill='yellow')
def
lineas(ventana):
v3.deiconify()
linea = Canvas(v3, width=210, height=210,
bg='white')
linea.pack(expand=YES, fill=BOTH)
linea.create_line(0, 200, 200, 0, width=10,
fill='black', )
linea.create_line(0, 0, 200, 200, width=10,
fill='black', )
boton2 =
Button(v1, text="Cerrar", relief=SOLID, bg='blue', command=lambda:
ejecutar(ocultar(v1)))
boton2.pack()
boton5 =
Button(v2, text="Cerrar", relief=SOLID, bg='green', command=lambda:
ejecutar(ocultar(v2)))
boton5.pack()
boton2 =
Button(v3, text="Cerrar", relief=SOLID, bg='red', command=lambda:
ejecutar(ocultar(v3)))
boton2.pack()
b1 =
Button(v0, text="Mostrar circulo", relief=FLAT, bg='white',
command=lambda: ejecutar(circulo(v1)))
b1.grid(row=1,
column=3)
b2 =
Button(v0, text="Mostrar rectangulo", relief=FLAT,
bg='white',command=lambda: ejecutar(rectangulo(v0)))
b2.grid(row=1,
column=2)
b3 =
Button(v0, text="Mostrar lineas", relief=FLAT, bg='white',
command=lambda: ejecutar(lineas(v0)))
b3.grid(row=1,
column=1)
v3.withdraw()
v2.withdraw()
v1.withdraw()
v0.mainloop()












No hay comentarios:
Publicar un comentario