16-03-2019, 12:19 AM
Hola, tengo un código para python 3.7.0, me piden hacer el triangulo de sierpinsky, pero no se que estoy haciendo mal, aquí esta el código.
from tkinter import *
from tkinter import ttk
class Aplicacion():
def __init__(self):
self.raiz = Tk()
self.raiz.title("Dibujos")
self.x1 = 100
self.y1 = 100
self.x2 = 50
self.y2 = 150
self.x3 = 150
self.y3 = 150
self.x4 = " "
self.y4 = " "
self.x5 = " "
self.y5 = " "
self.x6 = " "
self.y6 = " "
#self.l = 1000 #longuitd de linea.
#self.d = 40 # distancia entre lineas.
self.n = 1 # cantidad de lineas.
m = int(self.n)
self.cnvLienzo = Canvas(self.raiz, bg = "#05a", height=400, width=800)
self.btnLineaH = ttk.Button(self.raiz, text = "Linea horizontal" ,
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, n):
def sier(self, x1,y1,x2,y2,x3,y3,m):
if m == 1 :
self.cnvLienzo.create_line( self.x1 ,self.y1 ,
self.x2,self.y2 , fill = "red")
self.cnvLienzo.create_line( self.x1 ,self.y1 ,
self.x3,self.y3 , fill = "blue")
self.cnvLienzo.create_line( self.x3 ,self.y3 ,
self.x2,self.y2 , fill = "red")
else:
self.x4 = (self.x1 + self.x2)/2
self.y4 = (self.y1 + self.y2)/2
self.x5 = (self.x2 + self.x3)/2
self.y5 = (self.y2 + self.y3)/2
self.x6 = (self.x3 + self.x1)/2
self.y6 = (self.y3 + self.y1)/2
sier(self, x1,y1, x4,y4,x6,y6,m-1,fill = "red")
sier(self, x2,y2, x4,y4,x5,y5,m-1,fill = "blue")
sier(self, x3,y3, x6,y6,x5,y5,m-1,fill = "red" )
def main():
mi_app = Aplicacion()
return 0
if __name__ == '__main__':
main()
from tkinter import *
from tkinter import ttk
class Aplicacion():
def __init__(self):
self.raiz = Tk()
self.raiz.title("Dibujos")
self.x1 = 100
self.y1 = 100
self.x2 = 50
self.y2 = 150
self.x3 = 150
self.y3 = 150
self.x4 = " "
self.y4 = " "
self.x5 = " "
self.y5 = " "
self.x6 = " "
self.y6 = " "
#self.l = 1000 #longuitd de linea.
#self.d = 40 # distancia entre lineas.
self.n = 1 # cantidad de lineas.
m = int(self.n)
self.cnvLienzo = Canvas(self.raiz, bg = "#05a", height=400, width=800)
self.btnLineaH = ttk.Button(self.raiz, text = "Linea horizontal" ,
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, n):
def sier(self, x1,y1,x2,y2,x3,y3,m):
if m == 1 :
self.cnvLienzo.create_line( self.x1 ,self.y1 ,
self.x2,self.y2 , fill = "red")
self.cnvLienzo.create_line( self.x1 ,self.y1 ,
self.x3,self.y3 , fill = "blue")
self.cnvLienzo.create_line( self.x3 ,self.y3 ,
self.x2,self.y2 , fill = "red")
else:
self.x4 = (self.x1 + self.x2)/2
self.y4 = (self.y1 + self.y2)/2
self.x5 = (self.x2 + self.x3)/2
self.y5 = (self.y2 + self.y3)/2
self.x6 = (self.x3 + self.x1)/2
self.y6 = (self.y3 + self.y1)/2
sier(self, x1,y1, x4,y4,x6,y6,m-1,fill = "red")
sier(self, x2,y2, x4,y4,x5,y5,m-1,fill = "blue")
sier(self, x3,y3, x6,y6,x5,y5,m-1,fill = "red" )
def main():
mi_app = Aplicacion()
return 0
if __name__ == '__main__':
main()