AttributeError:'NoneType'对象没有属性'pack'

时间:2017-04-04 06:39:25

标签: python

我想在Python的GUI应用程序中添加一个视频,在单击按钮后读取新帧。但是我收到了这个错误:

  

AttributeError:'NoneType'对象没有属性'pack'。

当我取消注释pack方法时,错误消失,但会出现一个白色的空白窗口。

def show_vid(): 

     print cap
     print rdfile

     _ ,image = cap.read()

    cv2.imwrite("frame.jpg" , image)
    image=Image.open('F:\\MachineLearning\\\\frame.jpg')#creating a function
    img = ImageTk.PhotoImage(image)
    imglabel = Label(window, image=img)
    imglabel.grid(row=0 , column=0)#.pack().place(bordermode=OUTSIDE, x=10, y=100)  

2 个答案:

答案 0 :(得分:0)

这个函数调用 -

imglabel.grid(row = 0 , column = 0)

返回无。因此,当您尝试在其上调用pack()时,您会收到该错误。简单,不是吗?

更准确:我怀疑grid()永远不会返回任何东西。这是另一种说法,它返回无。您错误地使用了该功能。

编辑:

我对tkinter一无所知,但我相信你需要将你的函数调用分成两个单独的函数:

imglabel.grid(row=0 , column=0)  //this returns nothing, so you can't call another function here.
imglabel.pack().place(bordermode=OUTSIDE, x=10, y=100)

答案 1 :(得分:0)

让我想起了我刚刚做的事情:' 感谢您的帮助!

private void fillArrow(Canvas canvas, float x0, float y0, float x1, float y1) {
    paint.setStyle(Paint.Style.FILL);

    float deltaX = x1 - x0;
    float deltaY = y1 - y0;
    double distance = Math.sqrt((deltaX * deltaX) + (deltaY * deltaY));
    float frac = (float) (1 / (distance / 30));

    float point_x_1 = x0 + (float) ((1 - frac) * deltaX + frac * deltaY);
    float point_y_1 = y0 + (float) ((1 - frac) * deltaY - frac * deltaX);

    float point_x_2 = x1;
    float point_y_2 = y1;

    float point_x_3 = x0 + (float) ((1 - frac) * deltaX - frac * deltaY);
    float point_y_3 = y0 + (float) ((1 - frac) * deltaY + frac * deltaX);

    Path path = new Path();
    path.setFillType(Path.FillType.EVEN_ODD);

    path.moveTo(point_x_1, point_y_1);
    path.lineTo(point_x_2, point_y_2);
    path.lineTo(point_x_3, point_y_3);
    path.lineTo(point_x_1, point_y_1);
    path.lineTo(point_x_1, point_y_1);
    path.close();

    canvas.drawPath(path, paint);
}

..成为:

def popup():
    """The popup windows opening"""
    window = Toplevel()
    label = tk.Toplevel
    label.Toplevel()