Tkinter shows an SVG file

This script shows svg into tkinter. This is a feature I want to add in my Imagebrowser 1.4 app.

# show svg in tkinter

import tkinter as tk
from svglib.svglib import svg2rlg
from reportlab.graphics import renderPDF, renderPM
from PIL import Image, ImageTk

def get_svg(svg_file):
	drawing = svg2rlg(svg_file)
	renderPM.drawToFile(drawing, "temp.png", fmt="PNG")



class Root:
	def __init__(self):
		root = tk.Tk()
		img = Image.open('temp.png')
		pimg = ImageTk.PhotoImage(img)
		size = img.size
		frame = tk.Canvas(root, width=size[0], height=size[1])
		frame.pack()
		frame.create_image(0,0,anchor='nw',image=pimg)
		root.mainloop()

get_svg("disegno.svg")
root = Root()

an example of svg

How you see it in tkinter

The video of this script to put an svg into tkinter


Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.