I'm considering experimenting with canvas or more likely with tkpath.
I
want to create an interactive GUI program so that I can create
shapes and modify their properties.
So I need to be able to save all the items that are created and to
be able to load them back in again.
With the tk text widget saving can be done using the dump command and
loading isn't too difficult to do.
But I can't see an equivalent for canvas or for tkpath.
Do canvas or tkpath have support for loading/saving?
(If they don't I can envisage creating my own file format that
keeps track of each item but I don't want to reinvent if this is
already present.)
Mark Summerfield <m.n.summerfield@gmail.com> posted:
I'm considering experimenting with canvas or more likely with tkpath.
I
want to create an interactive GUI program so that I can create
shapes and modify their properties.
So I need to be able to save all the items that are created and to
be able to load them back in again.
With the tk text widget saving can be done using the dump command and
loading isn't too difficult to do.
But I can't see an equivalent for canvas or for tkpath.
Do canvas or tkpath have support for loading/saving?
(If they don't I can envisage creating my own file format that
keeps track of each item but I don't want to reinvent if this is
already present.)
The canvas (and tkpath as well, I guess) offers introspection so that you can indeed save the contents and load it in again. A source of inspiration might be tkpaint (see the Wiki), though I do not know the current status.
Regards,
Arjen
* Mark Summerfield <m.n.summerfield@gmail.com>
| On Wed, 19 Nov 2025 11:57:54 GMT, Arjen wrote:
| > The canvas (and tkpath as well, I guess) offers introspection so that you can
| > indeed save the contents and load it in again. A source of inspiration might
| > be tkpaint (see the Wiki), though I do not know the current status. --<snip-snip>--
| Unfortunately none of the links on that page
| https://wiki.tcl-lang.org/page/Tkpaint work.
| I'll see how far I get on my own.
For the canvas:
loop
canvas list all => all currently defined objects in stacking order
canvas type id => oval rect ...
canvas coords id => where is it
canvas itemconfigure id => what does it look like
should get you some way.
Can't say for tkpath, but the procedure would be similar.
HTH
R'
On Wed, 19 Nov 2025 11:57:54 GMT, Arjen wrote:
Mark Summerfield <m.n.summerfield@gmail.com> posted:
I'm considering experimenting with canvas or more likely with
tkpath. I
want to create an interactive GUI program so that I can create
shapes and modify their properties.
So I need to be able to save all the items that are created and to
be able to load them back in again.
With the tk text widget saving can be done using the dump command
and loading isn't too difficult to do.
But I can't see an equivalent for canvas or for tkpath.
Do canvas or tkpath have support for loading/saving?
(If they don't I can envisage creating my own file format that
keeps track of each item but I don't want to reinvent if this is
already present.)
The canvas (and tkpath as well, I guess) offers introspection so that
you can indeed save the contents and load it in again. A source of
inspiration might be tkpaint (see the Wiki), though I do not know the
current status.
Regards,
Arjen
Unfortunately none of the links on that page https://wiki.tcl-lang.org/page/Tkpaint work.
I'll see how far I get on my own.
Thanks.
For the canvas:
loop
canvas list all => all currently defined objects in stacking order
canvas type id => oval rect ...
canvas coords id => where is it
canvas itemconfigure id => what does it look like
should get you some way.
Do canvas or tkpath have support for loading/saving?
(If they don't I can envisage creating my own file format that
keeps track of each item but I don't want to reinvent if this is
already present.)
On Thu, 20 Nov 2025 10:36:27 +0100
Ralf Fassel <ralfixx@gmx.de> wrote:
[...]
For the canvas:
loop
canvas list all => all currently defined objects in stacking order
canvas type id => oval rect ...
canvas coords id => where is it
canvas itemconfigure id => what does it look like
should get you some way.
Except for window items, where it would take a bit more work, this code
works well serializing/deserializing canvas items:
# start
proc canvas_dump {c} {
lmap item [$c find all] {
set type [$c type $item]
# skip if item type is window
if {$type eq "window"} continue
set res [list $type [$c coords $item]]
foreach opt [$c itemconfigure $item] {
lappend res [lindex $opt 0] [lindex $opt end]
}
set res
}
}
proc canvas_restore {c dump} {
foreach item $dump {
$c create {*}$item
}
}
# end
This will copy items *appearance* from a canvas to another, but will
not copy behaviour. You have to instrospect bindings, at both canvas
and items level (tags and id's), to get a better copy.
Regards.
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,089 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 153:53:54 |
| Calls: | 13,921 |
| Calls today: | 2 |
| Files: | 187,021 |
| D/L today: |
3,760 files (944M bytes) |
| Messages: | 2,457,163 |