0

I am trying to insert an image(logo) in GIUs to display it in top left corner using grid and preferable in frame. When I do this code without demonstrator then it works perfectly but as soon I put it in Demonstrator the image disappears. Any Suggestion?

class TaskGUI():
    def __init__(self,master):
        header    = Frame(master, )
        header.grid(row=2,column=1,sticky=W)
        canvas= Canvas(header, bg= 'pink')
        Label(header, bg= 'blue' ).grid(row=1)
        canvas.grid(row=1,column=1)
        imgLogo = PhotoImage(file = 'logo.gif' )
        canvas.create_image(10,10, image= imgLogo, ancho= NW)


if __name__ == "__main__":
    top =Tk()
    top.geometry('10920x1080')
    top.title("Stel")
    top.grid()

    app = TaskGUI(top)

    top.mainloop()

I tried to use PIL libary but could not find any solution on this on either, I get this error:

    from PIL import  Image,ImageTk
File "C:\Program Files\Python\PIL\Image.py", line 57
    except ImportError, v:
                      ^
SyntaxError: invalid syntax
4

1 回答 1

2

您正在尝试使用 Python 3 运行代码,但 PIL 仅与 Python 2 兼容。

在 Python 3 中,捕获异常的语法与 Python 2 中的语法except ImportError as v相同except ImportError, v。请注意,更改它很可能无济于事,因为 PIL 中还有许多其他不兼容的东西。

但是,Pillow是与 Python 3 兼容的 PIL 的兼容分支。

于 2013-09-13T11:46:45.597 回答