Discussion:
A TkPath question
(too old to reply)
Helmut Giese
2024-10-10 19:17:51 UTC
Permalink
Hello out there,
I very much like TkPath and am trying to implement some control
widgets based on it. But I stumbled upon a problem: It seems that
there is no TkPath equivalent to the 'arc' command of the regular Tk
canvas. Below is a simplified example from the TkLib's
'controlwidgets' package:
----
package require Tk
package require tkpath

proc mkGUI {parent} {
set dialcolor lightgreen
set width [$c cget -width]
set xcentre [expr {$width*0.5}]
set ycentre [expr {$width*1.4}]
set t 1.15

set c [tkp::canvas $parent.c -width 250 -height 150 \
-background gray50]
pack $c
$c create arc \
[expr {$xcentre-$width*$t}] [expr {$ycentre-$width*$t}] \
[expr {$xcentre+$width*$t}] [expr {$ycentre+$width*$t}] \
-start 70.5 -extent 37 -style arc -outline $dialcolor \
-width [expr {$ycentre*0.245}]

return $c
}
set c [mkGUI ""]
----
Any ideas how to accomplish the same with TkPath would be highly
appreciated.
Helmut
Helmut Giese
2024-10-10 19:51:42 UTC
Permalink
To answer my own question: The 'path' item to the rescue. The
description isn't exactly exhaustive but after some experimentation I
came up with the following which is pretty close to my OP:
---
package require Tk
package require tkpath

proc mkGUI {parent} {
set c [tkp::canvas $parent.c -width 250 -height 150 \
-background gray50]
pack $c
$c create path {M 25 36 A 270 270 0 0 1 235 36 L 205 120 \
M 25 36 L 50 120 A 220 220 0 0 1 205 120} -fill lightgreen
return $c
}
set c [mkGUI ""]
---
So I'm a happy camper again
Helmut
greg
2024-10-11 04:20:51 UTC
Permalink
Post by Helmut Giese
Hello out there,
I very much like TkPath and am trying to implement some control
widgets based on it. But I stumbled upon a problem: It seems that
there is no TkPath equivalent to the 'arc' command of the regular Tk
canvas. Below is a simplified example from the TkLib's
----
package require Tk
package require tkpath
proc mkGUI {parent} {
set dialcolor lightgreen
set width [$c cget -width]
set xcentre [expr {$width*0.5}]
set ycentre [expr {$width*1.4}]
set t 1.15
set c [tkp::canvas $parent.c -width 250 -height 150 \
-background gray50]
pack $c
$c create arc \
[expr {$xcentre-$width*$t}] [expr {$ycentre-$width*$t}] \
[expr {$xcentre+$width*$t}] [expr {$ycentre+$width*$t}] \
-start 70.5 -extent 37 -style arc -outline $dialcolor \
-width [expr {$ycentre*0.245}]
return $c
}
set c [mkGUI ""]
----
Any ideas how to accomplish the same with TkPath would be highly
appreciated.
Helmut
Hello,
only the order changed


package require Tk
package require tkpath

proc mkGUI {parent} {
set dialcolor lightgreen

set c [tkp::canvas $parent.c -width 250 -height 150 -background gray50]
pack $c

set width [$c cget -width]
set xcentre [expr {$width * 0.5}]
set ycentre [expr {$width*1.4}]
set t 1.15

$c create arc \
[expr {$xcentre-$width*$t}] [expr {$ycentre-$width*$t}] \
[expr {$xcentre+$width*$t}] [expr {$ycentre+$width*$t}] \
-start 70.5 -extent 37 -style arc -outline $dialcolor \
-width [expr {$ycentre*0.245}]

return $c
}


set c [mkGUI .]

Loading...