Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

tkinter include svg in script

# pip install svglib

from svglib.svglib import svg2rlg
from reportlab.graphics import renderPM

from PIL import ImageTk, Image as PIL_image
from io import BytesIO
from tkinter import *

svg_content = """<?xml version="1.0" standalone="no"?>
<svg viewBox="0 0 480 150" style="background-color:#ffffff00" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" x="0px" y="0px" width="480" height="150">
    <path d="M 0 35.5 L 6.5 22.5 L 16 37 L 23 24 L 34.8 43.7 L 42.5 30 L 50.3 47 L 59.7 27.7 L 69 47 L 85 17.7 L 98.3 39 L 113 9.7 L 127.7 42.3 L 136.3 23.7 L 147 44.3 L 158.3 20.3 L 170.3 40.3 L 177.7 25.7 L 189.7 43 L 199.7 21 L 207.7 35 L 219 11 L 233 37 L 240.3 23.7 L 251 43 L 263 18.3 L 272.7 33.3 L 283 10 L 295 32.3 L 301.3 23 L 311.7 37 L 323.7 7.7 L 339.3 39 L 346.3 25.7 L 356.3 42.3 L 369.7 15 L 376.3 25.7 L 384 9 L 393 28.3 L 400.3 19 L 411.7 38.3 L 421 21 L 434.3 43 L 445 25 L 453 36.3 L 464.3 18.3 L 476.2 40.3 L 480 33.5 L 480 215 L 0 215 L 0 35.5 Z" fill="#175720"/>
</svg>"""

drawing = svg2rlg(path=  BytesIO(bytes(svg_content,'ascii')) )
out = BytesIO()
renderPM.drawToFile(drawing, out, fmt="PNG")

tk = Tk()
img = PIL_image.open(out)
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()
Comment

PREVIOUS NEXT
Code Example
Python :: how to set numerecal index in pandas 
Python :: pandas correlation matrix between one column and all others 
Python :: pandas dataframe add two columns int and string 
Python :: pyhton image resize 
Python :: Group based sort pandas 
Python :: python - count number of occurence in a column 
Python :: is in python 
Python :: code coverage pytest as html 
Python :: tuple index in python 
Python :: pandas series top 5 percent 
Python :: pyton do while loop+ 
Python :: convert integer to binary in python 
Python :: create a virtual environment in python3 
Python :: import this 
Python :: create python executable 
Python :: making your own range function in python 
Python :: python for in for in 
Python :: python check variable size in memory 
Python :: python select last item in list 
Python :: dict comprehension 
Python :: how to get SITE_ID in django....shell 
Python :: merge two columns name in one header pandas 
Python :: how to split string by list of indexes python 
Python :: python synonym library 
Python :: how to scale an array between two values python 
Python :: python sort a 2d array by custom function 
Python :: concatenation of array in python 
Python :: web driver module in python 
Python :: Username Promt using Python with Character Limit 
Python :: python np get indices where value 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =