0

所以,我试图简化我的工作,结果在我第一次问的时候就犯了一个错误。我想问的是为什么这条线不起作用?

self.canvas.create_line(A,B,C,D)

现在的问题是具体的,不会对其他人有用,所以我不介意你删除这篇文章。不幸的是我不能删除它。

from tkinter import Tk, Canvas, Frame, BOTH


class Lsystem(Frame):

    def rule_1(self): #A0
        self.r.append(1)
        self.r.append(0)

        A = self.lastCo[0][0]
        B = self.lastCo[0][1]
        C = self.lastCo[0][0]+self.length
        D = self.lastCo[0][1]+self.length

        self.canvas.create_line(A,B,C,D)


    def rule_2(self): #B1
        self.r.append(1)

    def lindenL(self, num):
        x = 0
        while x < num:
            for cycle in list(range(len(self.q))):
                if self.q[0] == 1: self.rule_1()
                else: self.rule_2()
                self.q.pop(0)
            self.q = self.r
            #print (self.q)
            x += 1

        return self.q

    def setVariables(self):
        self.r = []
        self.q = [1]
        self.line = []
        self.length = 100
        self.maxCo = [800, 600]
        self.lastCo = [[400,600],[0,0]] #0 is A(0), 1 is B(1)

    def __init__(self, parent):
        Frame.__init__(self, parent)   

        self.setVariables()
        self.parent = parent        
        self.initUI()

        print(self.lindenL(2))

    def initUI(self):
        self.parent.title("Shapes")        
        self.pack(fill=BOTH, expand=1)
        self.canvas = Canvas(self)

        self.draw()

        self.canvas.pack()

    def draw(self):
        pass
        #self.canvas.create_line(self.calcCoA())


def main():

    root = Tk()
    ex = Lsystem(root)
    root.geometry("800x600+300+300")
    root.mainloop()  


if __name__ == '__main__':
    main()  
4

1 回答 1

2

你忘了收拾画布

例如。

  canvas = Canvas(self)
  canvas.pack()
于 2012-05-10T06:54:20.003 回答