sábado, 21 de marzo de 2020

Interfaz de figuras



# -*- coding: utf-8 -*-

from tkinter import *

def _from_rgb(rgb):

  return "#%02x%02x%02x" % rgb


v0= Tk()#ventana principalv0.title("Ventana Principal")
v0.configure(bg=_from_rgb((0, 250, 200)))
v0.geometry("700x800")#tamaño ventana

def mostrar(num):
    v1=Toplevel(v0)
    v1.title("ventana hija")
    v1.config(bg="green")
    v1.protocol("WN_DELETE_WINDOW", "onexit")
    v1.geometry("400x400")


    if num==1:
        canvas1=Canvas(v1, width=200, height=210, bg="white")
        canvas1.create_line(0,900,200,0,width=10,fil="red")
        canvas1.pack(expand=YES,fill=BOTH)
        b2=Button(canvas1,text="Ocultar",command=lambda:ejecutar(ocultar(v1)))
        b2.place(x=35,y=50)
        v1.deiconify()
    elif num == 2:
        canvas2 = Canvas(v1, width=240, height=210, bg="white")
        canvas2.create_oval(50, 50, 200, 200, width=10, fil="blue")
        canvas2.pack(expand=YES, fill=BOTH)
        b2 = Button(canvas2, text="Ocultar", command=lambda: ejecutar(ocultar(v1)))
        b2.place(x=35, y=250)
        v1.deiconify()
    elif num == 3:
        canvas3 = Canvas(v1, width=240, height=210, bg="white")
        canvas3.create_rectangle(10, 10, 200, 200, width=10, fil="yellow")
        canvas3.pack(expand=YES, fill=BOTH)
        b2 = Button(canvas3, text="Ocultar", command=lambda: ejecutar(ocultar(v1)))
        b2.place(x=35, y=250)
        v1.deiconify()




def ocultar(ventana):
    ventana.destroy()
def ejecutar (f):
    v0.after(200,f)




b1=Button(v0,text="Hacer Linea ",command=lambda:ejecutar(mostrar(1)))
b1.place(x=50,y=50)


b2=Button(v0,text="Hacer Circulo",command=lambda:ejecutar(mostrar(2)))
b2.place(x=35,y=100)

b3=Button(v0,text="Hacer Rectangulo",command=lambda:ejecutar(mostrar(3)))
b3.place(x=35,y=150)





v0.mainloop()

No hay comentarios.:

Publicar un comentario