2

I wanted to add Checkbox in the ttk::treeview ?

i read few documents and found its not possible to add check box to add to ttk::treeview. Is there any other option to do this ?

Macmade
  • 52,708
  • 13
  • 106
  • 123
Abarna R
  • 21
  • 1
  • 2

3 Answers3

1

The treeview widget simply isn't sophisticated enough to do it, not without a lot of work. (You might be able to do an approximation of it by doing styles that define what checked and unchecked lines look like and using a binding to switch between them… but that would be pretty horrific and fragile.) Yes, this means that you can't do everything with it, but that in turn also keeps the widget's API simpler to learn. That's always a tricky design tradeoff.

Your best bet is probably TkTreeCtrl, which has a reputation of being able to do just about anything that you might conceive of ever wanting to do with a tree (or table, or grid) widget. Ever. As I understand it though (not being a user of it) it's rather tricky to use; I've heard it recommended to me that TkTreeCtrl always be wrapped with extra code to restrict its API to the particular purpose you need.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
1

I do use checkboxes in ttk:treeview with a vanilla code, but in the first column.

In the first column of the treeview (referred as #0, or "tree" ) , you can specify an image (let us say icon_checked and icon_unchecked) as you would for a label.

$win.tv item $item -image icon_checked

So much for the graphical part. For the not-so-dirty part:

  • create a list with a status for each row of your treeview (eg: "tvstatus" { 0 0 0 1 0})
  • create a procedure "tv_refresh" that update each row depending on the list "tvstatus"
  • create a binding on the treeview that : 1 changes the value of one item of the list "tvstatus" 2 call "tv_refresh"

Precise what you want to ask to the user for a more specific answer.

Andrei Petrenko
  • 3,922
  • 3
  • 31
  • 53
Ant
  • 11
  • 1
0

I found a solution on comp.lang.tcl. See https://groups.google.com/d/msg/comp.lang.tcl/VwG4_7-1538/MWzhZiVcoecJ

hae
  • 256
  • 2
  • 5
  • 1
    You should quote from that article as well as linking. Google URLs aren't guaranteed to remain valid for all time. (Alas.) – Donal Fellows Feb 02 '14 at 23:41