Как задать размеры изображения tksvg в pix?
Простой пример:
import tkinter as tk
import tksvg
window = tk.Tk()
svg_image = tksvg.SvgImage(master=window, file="128.svg", scale=1)
label = tk.Label(bg='#CCCCCC', image=svg_image, borderwidth=0, relief="solid")
print(label.winfo_reqwidth(), label.winfo_reqheight())
label.pack()
window.mainloop()
128.svg - 128х128 pix.
Вопрос: Как задать размеры изображения tksvg в pix?
Ответы (1 шт):
Размер в пикселях можно указать через параметр scaletowidth (или scaletoheight).
Из мануала Tk 8.7:
svg -dpi dpiValue -scale scaleValue -scaletowidth width -scaletoheight height
dpiValueis used in conversion between given coordinates and screen resolution. The value must be greater than0and the default value is96.scaleValueis used to scale the resulting image. The value must be greater than0and the default value is1.widthandheightare the width or height that the image will be adjusted to.
Only one parameter among -scale, -scaletowidth and -scaletoheight can be given at a time
and the aspect ratio of the original image is always preserved.