Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Images not Updating in ttk::treeview when Using Tags

1,062 views
Skip to first unread message

Sue

unread,
Mar 9, 2012, 11:12:14 AM3/9/12
to
Hello I am creating a very simple ttk::treeview example in which I
would like an image to appear and change when the user selects it. I
can get the image to originally appear. And I can get the text color
to change using a tag, but I can't get the image to switch. In the
version I am running tcl 8.5. Is this a bug or am I doing something
incorrectly?

toplevel .bwin
ttk::treeview .bwin.tree
pack .bwin.tree
.bwin.tree insert {} end -id test1 -text "Test1" -image [ image create
photo -file "closeX.png"] -tags "on off"
.bwin.tree tag configure on -foreground red
.bwin.tree tag configure on -image [ image create photo -file "mouse-
right-12.gif"]


Thanks in advance for any and all help.

Joe English

unread,
Mar 9, 2012, 3:02:50 PM3/9/12
to
Sue asked:
> Hello I am creating a very simple ttk::treeview example in which I
> would like an image to appear and change when the user selects it. I
> can get the image to originally appear. And I can get the text color
> to change using a tag, but I can't get the image to switch. In the
> version I am running tcl 8.5. Is this a bug or am I doing something
> incorrectly?
>
> toplevel .bwin
> ttk::treeview .bwin.tree
> pack .bwin.tree
> .bwin.tree insert {} end -id test1 -text "Test1" -image [ image create
> photo -file "closeX.png"] -tags "on off"
> [...]

If an -image is specified for an item, it takes
precedence over any -image specified on the tags.
Specify "-image ... closeX.png ..." on a tag instead,
and it should work as desired.

Note also that in the case of multiple tags, at present
the tag with the highest priority takes precedence;
the order in which they appear in -tags does not matter.
That is, "-tags" is a tag set, not a tag list.
Tag priority is determined by creation order,
first tag created has the highest priority.


--Joe English

Sue

unread,
Mar 12, 2012, 2:07:18 PM3/12/12
to
Joe,

Thank you for your reply. I did as you instructed and I still am not
seeing the image as I would expect on a tag configure command. Here
is the code snippet. Am I still doing something wrong here?

toplevel .bwin
ttk::treeview .bwin.tree
pack .bwin.tree
package require tkpng
.bwin.tree insert {} end -id test1 -text "Test1" -tags "chk"
.bwin.tree insert {} end -id test2 -text "Test2" -tags "chk1"
.bwin.tree tag configure chk -foreground red -image [ image create
photo -file "closeX.png"]
.bwin.tree tag configure chk1 -image [ image create photo -file
"closeX.png"]


Thank you again,
Sue

Joe English

unread,
Mar 12, 2012, 4:22:34 PM3/12/12
to
Sue asked:
>
> Thank you for your reply. I did as you instructed and I still am not
> seeing the image as I would expect on a tag configure command. Here
> is the code snippet. Am I still doing something wrong here?
>
> toplevel .bwin
> ttk::treeview .bwin.tree
> pack .bwin.tree
> package require tkpng
> .bwin.tree insert {} end -id test1 -text "Test1" -tags "chk"
> .bwin.tree insert {} end -id test2 -text "Test2" -tags "chk1"
> .bwin.tree tag configure chk -foreground red -image [ image create
> photo -file "closeX.png"]
> .bwin.tree tag configure chk1 -image [ image create photo -file
> "closeX.png"]


One possibility is that the above snippet uses the same image
for both tags :-)

Another possibility is that you may be running into a treeview bug
whereby the display doesn't always refresh in response to
tag changes. If so, you can use [event generate $tv <Expose>]
to force a redisplay.

Anyway, this works for me (Tk 8.5.11):

package require Tk 8.5.11
package require tkpng

set path /usr/share/icons/hicolor/16x16/stock/generic
image create photo close -file $path/stock_close.png
image create photo mark -file $path/stock_mark.png

pack [ttk::treeview .tv] -expand true -fill both
.tv tag configure tag1 -image close
.tv tag configure tag2 -image mark

.tv insert {} end -id test1 -text "Test1" -tags {tag1}
.tv insert {} end -id test2 -text "Test2" -tags {tag2}

bind .tv <ButtonPress-1> { %W item [%W identify item %x %y] -tags tag1 }
bind .tv <ButtonPress-2> { %W item [%W identify item %x %y] -tags tag2 }


--Joe English

Sue

unread,
Mar 12, 2012, 9:02:28 PM3/12/12
to
Joe thank you again for your reply. Ok, so I tried the code you have
above. I think you have a typo in the last two "bind" lines. I
believe the one "item" should read "row":
bind .tv <ButtonPress-1> { %W item [%W identify row %x %y] -tags
tag1 }
bind .tv <ButtonPress-2> { %W item [%W identify row %x %y] -tags
tag2 }

Any way I tried your code snippet, that didn't work, so I tried the
"event generate $tv <Expose>" command and still no image. I am
running on Tk 8.5.6. Any one else using Tk 8.5.6? If so, can you run
this code and see an image?

Thank you,
Sue

Joe English

unread,
Mar 13, 2012, 12:50:32 PM3/13/12
to
Sue wrote:
> [...]
> Joe thank you again for your reply. Ok, so I tried the code you have
> above. I think you have a typo in the last two "bind" lines. I
> believe the one "item" should read "row":
> [...]
> Any way I tried your code snippet, that didn't work, so I tried the
> "event generate $tv <Expose>" command and still no image. I am
> running on Tk 8.5.6.

Aha! That explains it.

Tk 8.5.0 incorporated the Tile extension at a point when
the treeview widget was only partly working. If you can,
upgrade to 8.5.9 or later, preferably 8.5.11. ttk::treeview
widgets work much better in the current version.

I'd have to check, but I think the only way to specify an
image in that version was by configuring the item itself.


--Joe

Sue

unread,
Mar 13, 2012, 1:06:00 PM3/13/12
to

> I'd have to check, but I think the only way to specify an
> image in that version was by configuring the item itself.
>
> --Joe

Ok, please check for me. And let me know how I would go about
configuring this if it isn't too much work. I don't know how soon we
will be upgrading out tcl/tk. Thank you for your help.

Sue
0 new messages