元组索引超出范围Tkinter

时间:2013-05-15 10:31:58

标签: graph indexing plot tkinter tuples

所以我有一个程序应该将一个函数作为输入并在Tkinter画布上绘制它。

    def draw(self):
    self.canvas.delete(ALL)
    for n, i in enumerate(self.sav):
        self.function, colour = self.sav_func[n]
        i = self.p1(i)
        i = self.p2(i, self.function, colour)
        if i != [0]:
            try:
                self.canvas.create_line(i, fill = colour)
            except TclError as err:
                tkMessageBox.showerror(TclError, err)
                self.sav.remove(self.sav[len(self.sav)-1])
                self.sav_func.remove(self.sav_func[len(self.sav_func)-1])

本节给出了以下错误:

    Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
    return self.func(*args)
  File "D:/Google Drive/assign2_2-1.py", line 113, in add_func
    self.redraw_all()
  File "D:/Google Drive/assign2_2-1.py", line 132, in redraw_all
    self.draw()
  File "D:/Google Drive/assign2_2-1.py", line 145, in draw
    self.canvas.create_line(i, fill = colour)
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 2201, in create_line
    return self._create('line', args, kw)
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 2182, in _create
    cnf = args[-1]
IndexError: tuple index out of range

从我可以收集的内容来看,与输出数量不匹配的输入数量有关,但我仍然有点迷失。帮助会很棒!

1 个答案:

答案 0 :(得分:0)

看起来i没有足够的值。要创建一条线,它需要四个值:x1,y1,x2,y2。