AJN
AJN

Reputation: 1206

Tkinter Treeview cannot edit more that one column

I use a Tkinter TreeView that I populate with data from a file.

The result is 6 columns of prefilled numeric data for each row. Some rows has a single column value, others has multiple columns filled with data, editable by the user (upon mouse right click).

For rows with single editable column, I use the following piece of code:

...
self.tree.insert(id2 , 2,    text=key2.strip('\r\n'), \
  values=("","","10","","",""), \
  tags=('','','tag3','','',''))
  self.tree.tag_bind(('','','tag3','','',''), '<Button-3>', self.popupEntry)
...

Result: (OK) If right click then dialogbox popup with text entry, upon validation, the column of he corresponding row is successfully filled with the new value. This works for any single value tuple "tags".

But, for rows with more that one editable column I modified the previous code as follow:

...
self.tree.insert(id2 , 2,    text=key2.strip('\r\n'), \
  values=("","","10","","","10"), \
  tags=('','','tag3','','','tag6'))
  self.tree.tag_bind(('','','tag3','','','tag6'), '<Button-3>', self.popupEntry)
...

Result: (Not OK) No reaction to mouse Right click, nothing happens

Desired behavior: - for rows with 2 or more editable columns, right-click to spawn dialogbox with 2 text entries, upon validation, the 2 column values are filled.

Something like that: enter image description here

Popup code:

   def popupEntry(self, event):
        result = tkSimpleDialog.askinteger("New value", "Please enter a new numeric value")
        if result:
            self.tree.item(self.tree.focus(), values=self.tag_to_val(self.tree.item(self.tree.focus(), 'tags'), result))

Upvotes: 0

Views: 1149

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385970

You can't bind to a group of tags like that. You must create a binding for each individual tag.

Upvotes: 2

Related Questions