Tk 9: image -format svg -scaletowidth not working?

Liste des GroupesRevenir à cl tcl 
Sujet : Tk 9: image -format svg -scaletowidth not working?
De : mark (at) *nospam* qtrac.eu (Mark Summerfield)
Groupes : comp.lang.tcl
Date : 08. Jul 2024, 10:52:26
Autres entêtes
Message-ID : <MpadnXqNUoFHKxb7nZ2dnZfqnPqdnZ2d@brightview.co.uk>
User-Agent : Pan/0.154 (Izium; 517acf4)
I am trying to use the -format svg -scaletowidth option without success.

Given this svg file "test.svg" (copied from W3CSchools):

<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
   <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4"
fill="yellow" />
</svg>

This program works fine:

#!/usr/bin/env wish9
proc icon {svg {width 0}} {
    set opt [expr {$width ? "-format svg -scaletowidth $width" : ""}]
    image create photo -file $svg {*}$opt
}
ttk::button .button -command {destroy .} -image [icon test.svg]
grid .button

But if I want to scale the image to 24 pixels (e.g., for a menu item):

#!/usr/bin/env wish9
proc icon {svg {width 0}} {
    set opt [expr {$width ? "-format svg -scaletowidth $width" : ""}]
    image create photo -file $svg {*}$opt
}
ttk::button .button -command {destroy .} -image [icon test.svg 24]
grid .button

It fails with this error:

Error in startup script: unknown option "-scaletowidth"
    while executing
"image create photo -file $svg {*}$opt"
    (procedure "icon" line 3)
    invoked from within
"icon test.svg 24"
    invoked from within
"ttk::button .button -command {destroy .} -image [icon test.svg 24]"
    (file "./svgtest2.tcl" line 8)

Can someone tell me what I'm doing wrong?

I'm using Tcl/Tk 9.0b2 on Debian Linux.

Date Sujet#  Auteur
8 Jul 24 * Tk 9: image -format svg -scaletowidth not working?9Mark Summerfield
8 Jul 24 `* Re: Tk 9: image -format svg -scaletowidth not working?8Ralf Fassel
8 Jul 24  +- Re: Tk 9: image -format svg -scaletowidth not working?1Harald Oehlmann
9 Jul 24  `* Re: Tk 9: image -format svg -scaletowidth not working?6Mark Summerfield
9 Jul 24   +- Re: Tk 9: image -format svg -scaletowidth not working?1Harald Oehlmann
9 Jul 24   `* Re: Tk 9: image -format svg -scaletowidth not working?4nemethi
9 Jul 24    `* Re: Tk 9: image -format svg -scaletowidth not working?3Mark Summerfield
9 Jul 24     `* Re: Tk 9: image -format svg -scaletowidth not working?2nemethi
10 Jul 24      `- Re: Tk 9: image -format svg -scaletowidth not working?1Mark Summerfield

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal