from tkinter import * from tkinter import ttk k=int(input("Ingrese el valor: ")) X1=200 Y1=100 X2 = 50 Y2 = 300 X3 = 500 Y3 = 200
class Aplicacion(): def init(self): self.raiz = Tk() self.raiz.title("Dibujos")
from tkinter import *
from tkinter import ttk
k=int(input("Ingrese el valor: "))
X1=200
Y1=100
X2 = 50
Y2 = 300
X3 = 500
Y3 = 200
class Aplicacion():
def __init__(self):
self.raiz = Tk()
self.raiz.title("Dibujos")
self.cnvLienzo = Canvas(self.raiz, bg = "white", height=400, width=800)
self.btnLineaH = ttk.Button(self.raiz,
text = "Trángulo nivel {}".format(k) ,
command = self.dibujeLineaH)
self.cnvLienzo.pack(side=TOP, fill=BOTH, expand=True,
padx=5, pady=5)
self.btnLineaH.pack(side=TOP, fill=BOTH, expand=True,
padx=5, pady=5)
self.raiz.mainloop()
def dibujeLineaH(self):
def sier(m,x1,y1,x2,y2,x3,y3):
if m == 1 :
self.cnvLienzo.create_line( x1 ,y1 ,
x2,y2)
self.cnvLienzo.create_line( x1 ,y1 ,
x3,y3)
self.cnvLienzo.create_line( x3 ,y3 ,
x2,y2)
else:
x4 = (x1 +x2)/2
y4 = (y1 + y2)/2
x5 = (x2 + x3)/2
y5 = (y2 + y3)/2
x6 = (x3 + x1)/2
y6 = (y3 + y1)/2
sier(m-1, x1,y1, x4,y4,x6,y6, )
sier(m-1, x2,y2, x4,y4,x5,y5, )
sier(m-1, x3,y3, x6,y6,x5,y5, )
sier(k,X1,Y1,X2,Y2,X3,Y3 )
def main():
mi_app = Aplicacion()
return 0
if __name__ == '__main__':
main()
def main(): mi_app = Aplicacion() return 0
if name == 'main': main()