Python TkinterTreectrl drag items
I am writing a program in Python to allow me to browse through the experimental data I have taken, and also view metadata associated with the experimental conditions for each dataset.
Despite being rather a novice programmer, so far everything is working well - I can add items, remove items, select them etc etc.
However, I cannot work out how to allow the dragging of items to new locations in the tree. I have found in the documentation many references to drag images, and at the moment I can drag a tantalizing dotted outline around. But I cannot find the events which would be generated on a drag and drop. The closest I find in the manual is the following set of events:
<Drag-begin> <Drag-receive> <Drag-end>: Generated whenever the user drag-and-drops a file into a directory. This event is generated by the filelist-bindings.tcl library code, which is not used by default.
I do not know how to use the "filelist-bindings.tcl library code", but I am not sure this is the correct approach anyway.
In a related query - I thought one way to solve this and similar problems would be to send every event generated by my Treectrl widget to stdout. Is there a way to do this?
A minimal working example here would be rather too large to be of any use, but an excerpt may help:
# add callbacks for Edit events self.t.notify_install('<Edit-begin>') self.t.notify_bind('<Edit-begin>', self.edit_begin) self.t.notify_install('<Edit-accept>') self.t.notify_bind('<Edit-accept>', self.edit_accept) self.t.notify_install('<Edit-end>') self.t.notify_bind('<Edit-end>', self.edit_end) # add callbacks for mouse clicks self.t.bind('<Button-1>', self.OnLeftClick) self.t.bind('<Button-3>', self.OnRightClick) # add callbacks for drag events self.t.notify_install('<Drag-begin>') self.t.bind('<Drag-begin>', self.OnDrag) self.t.notify_install('<Drag-recieve>') self.t.bind('<Drag-recieve>', self.OnDrag) self.t.notify_install('<Drag-end>') self.t.bind('<Drag-end>', self.OnDrag)
Callbacks for Edit events and mouse clicks work fine, attempting to bind the drag events generates _tkinter.TclError: bad event type or keysym "Drag"
Ignoring the fact that this question is not the newest one - is there a specific reason why you use self.t.bind instead of self.t.notify_bind?
For me this looks pretty like the point where the Interface to tktreecrtl from Michael is not using the wrapper functionality but attempting to directly bind <Drag-begin> to a Treectrl instance which is based on tkinter.Widget
- Source Extract:
tkinter.Widget has no possibility to find a '' event as this is generated inside tktreectrl libraries. So you get the
bad event type or keysym "Drag"
Changing to self.t.notify_bind should solve your problem.