Putting .SVG images into tkinter Frame

前端 未结 2 1020
刺人心
刺人心 2020-12-17 17:25

I have been trying to put the image from https://betacssjs.chesscomfiles.com/bundles/web/favicons/safari-pinned-tab.f387b3f2.svg into a Tkinter frame. I found from the post

2条回答
  •  佛祖请我去吃肉
    2020-12-17 17:59

    I've managed to do it using svglib:

    from svglib.svglib import svg2rlg
    from reportlab.graphics import renderPDF, renderPM
    
    drawing = svg2rlg("safari-pinned-tab.f387b3f2.svg")
    renderPM.drawToFile(drawing, "temp.png", fmt="PNG")
    
    
    from tkinter import *
    
    tk = Tk()
    
    
    from PIL import Image, ImageTk
    
    img = Image.open('temp.png')
    pimg = ImageTk.PhotoImage(img)
    size = img.size
    
    
    frame = Canvas(tk, width=size[0], height=size[1])
    frame.pack()
    frame.create_image(0,0,anchor='nw',image=pimg)
    
    tk.mainloop()
    
    

提交回复
热议问题