Circulo:
Código:
from Tkinter import *
v1 = Tk()
v1.title("Figura")
v1.config(bg="white")
v1.geometry("250x270")
def ejecutar(f):
v1.after(200, f)
def cir(ven):
circulo = Canvas(v1,width=210, height=210, bg="white")
circulo.pack()
circulo.create_oval(10, 10, 200, 200, width=3,fill="blue")
def ocultar(ventana):
v1.withdraw()
br = Button(v1, text="Ver circulo", relief=FLAT,bg='white',command=lambda: ejecutar (cir(v1)))
br.pack()
bc = Button(v1, text="Cerrar",relief=FLAT,bg='white', command=lambda: ejecutar(ocultar(v1)))
bc.pack(side = BOTTOM)
v1.mainloop()
_________________________________________________________________________________
Cuadrado:
Código:
from Tkinter import *
v1 = Tk()
v1.title("Figura")
v1.config(bg="white")
v1.geometry("250x270")
def ejecutar(f):
v1.after(200, f)
def recta(ven):
rec = Canvas(width=210, height=210,bg='white')
rec.pack()
rec.create_rectangle(10, 10, 200, 200, width=5, fill="blue")
def ocultar(ventana):
v1.withdraw()
br = Button(v1, text="ver rectangulo",relief=FLAT,bg='black', command=lambda: ejecutar (recta(v1)),fg='#ffffff')
br.pack()
bc = Button(v1, text="Cerrar",relief=FLAT,bg='black', command=lambda: ejecutar(ocultar(v1)),fg='#ffffff')
bc.pack(side = BOTTOM)
v1.mainloop()
_________________________________________________________________________________
Lineas:
Código:
from Tkinter import *
v1 = Tk()
v1.title("Figura")
v1.config(bg="white")
v1.geometry("250x270")
def ejecutar(f):
v1.after(200, f)
def recta(ven):
linea = Canvas(width=210, height=210, bg='white')
linea.pack()
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 ocultar(ventana):
v1.withdraw()
br = Button(v1, text="Ver lineas",relief=FLAT,bg='blue', command=lambda: ejecutar (recta(v1)),fg='#ffffff')
br.pack()
bc = Button(v1, text="Cerrar",relief=FLAT,bg='blue', command=lambda: ejecutar(ocultar(v1)),fg='#ffffff')
bc.pack(side = BOTTOM)
v1.mainloop()
_________________________________________________________________________________
Todo en uno:
Código:
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="white")
circulo.pack()
cuadro = circulo.create_oval(10, 10, 200, 200, width=3,fill="blue")
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='black')
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', dash=(4, 4))
linea.create_line(0, 0, 200, 200, width=10, fill='black',dash=(4, 4))
boton2= Button(v1, text="Cerrar",relief=SOLID,bg='green',cursor="box_spiral", command=lambda: ejecutar(ocultar(v1)))
boton2.pack()
boton5= Button(v2, text="Cerrar",relief=SOLID,bg='red',cursor="pencil", command=lambda: ejecutar(ocultar(v2)))
boton5.pack()
boton2= Button(v3, text="Cerrar",relief=SOLID,bg='blue',cursor="umbrella", command=lambda: ejecutar(ocultar(v3)),fg='#ffffff')
boton2.pack()
b1=Button(v0,text="Mostrar circulo",relief=FLAT,bg='white',cursor="sizing",command=lambda: ejecutar(circulo(v1)))
b1.grid(row=1,column=3)
b2=Button(v0,text="Mostrar rectangulo",relief=FLAT,bg='black',cursor="hand1",command=lambda: ejecutar(rectangulo(v0)),fg='#ffffff')
b2.grid(row=1,column=2)
b3=Button(v0,text="Mostrar lineas",relief=FLAT,bg='white',cursor="hand2",command=lambda: ejecutar(lineas(v0)))
b3.grid(row=1,column=1)
v3.withdraw()
v2.withdraw()
v1.withdraw()
v0.mainloop()
Más conocimiento:
https://github.com/eliluminado/Guia-Tkinter/blob/master/Interfaz%20grafica%20con%20Tkinter.wiki
from Tkinter import *
v1 = Tk()
v1.title("Figura")
v1.config(bg="white")
v1.geometry("250x270")
def ejecutar(f):
v1.after(200, f)
def cir(ven):
circulo = Canvas(v1,width=210, height=210, bg="white")
circulo.pack()
circulo.create_oval(10, 10, 200, 200, width=3,fill="blue")
def ocultar(ventana):
v1.withdraw()
br = Button(v1, text="Ver circulo", relief=FLAT,bg='white',command=lambda: ejecutar (cir(v1)))
br.pack()
bc = Button(v1, text="Cerrar",relief=FLAT,bg='white', command=lambda: ejecutar(ocultar(v1)))
bc.pack(side = BOTTOM)
v1.mainloop()
_________________________________________________________________________________
Cuadrado:
from Tkinter import *
v1 = Tk()
v1.title("Figura")
v1.config(bg="white")
v1.geometry("250x270")
def ejecutar(f):
v1.after(200, f)
def recta(ven):
rec = Canvas(width=210, height=210,bg='white')
rec.pack()
rec.create_rectangle(10, 10, 200, 200, width=5, fill="blue")
def ocultar(ventana):
v1.withdraw()
br = Button(v1, text="ver rectangulo",relief=FLAT,bg='black', command=lambda: ejecutar (recta(v1)),fg='#ffffff')
br.pack()
bc = Button(v1, text="Cerrar",relief=FLAT,bg='black', command=lambda: ejecutar(ocultar(v1)),fg='#ffffff')
bc.pack(side = BOTTOM)
v1.mainloop()
_________________________________________________________________________________
Lineas:
Código:
from Tkinter import *
v1 = Tk()
v1.title("Figura")
v1.config(bg="white")
v1.geometry("250x270")
def ejecutar(f):
v1.after(200, f)
def recta(ven):
linea = Canvas(width=210, height=210, bg='white')
linea.pack()
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 ocultar(ventana):
v1.withdraw()
br = Button(v1, text="Ver lineas",relief=FLAT,bg='blue', command=lambda: ejecutar (recta(v1)),fg='#ffffff')
br.pack()
bc = Button(v1, text="Cerrar",relief=FLAT,bg='blue', command=lambda: ejecutar(ocultar(v1)),fg='#ffffff')
bc.pack(side = BOTTOM)
v1.mainloop()
_________________________________________________________________________________
Todo en uno:
Código:
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="white")
circulo.pack()
cuadro = circulo.create_oval(10, 10, 200, 200, width=3,fill="blue")
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='black')
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', dash=(4, 4))
linea.create_line(0, 0, 200, 200, width=10, fill='black',dash=(4, 4))
boton2= Button(v1, text="Cerrar",relief=SOLID,bg='green',cursor="box_spiral", command=lambda: ejecutar(ocultar(v1)))
boton2.pack()
boton5= Button(v2, text="Cerrar",relief=SOLID,bg='red',cursor="pencil", command=lambda: ejecutar(ocultar(v2)))
boton5.pack()
boton2= Button(v3, text="Cerrar",relief=SOLID,bg='blue',cursor="umbrella", command=lambda: ejecutar(ocultar(v3)),fg='#ffffff')
boton2.pack()
b1=Button(v0,text="Mostrar circulo",relief=FLAT,bg='white',cursor="sizing",command=lambda: ejecutar(circulo(v1)))
b1.grid(row=1,column=3)
b2=Button(v0,text="Mostrar rectangulo",relief=FLAT,bg='black',cursor="hand1",command=lambda: ejecutar(rectangulo(v0)),fg='#ffffff')
b2.grid(row=1,column=2)
b3=Button(v0,text="Mostrar lineas",relief=FLAT,bg='white',cursor="hand2",command=lambda: ejecutar(lineas(v0)))
b3.grid(row=1,column=1)
v3.withdraw()
v2.withdraw()
v1.withdraw()
v0.mainloop()
Más conocimiento:
https://github.com/eliluminado/Guia-Tkinter/blob/master/Interfaz%20grafica%20con%20Tkinter.wiki
Comentarios
Publicar un comentario