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.

At the heart of this program is the TkinterTreectrl widget, a wrapper for tk treectrl

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-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_bind('<Edit-begin>', self.edit_begin)
    self.t.notify_bind('<Edit-accept>', self.edit_accept)
    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.bind('<Drag-begin>', self.OnDrag)
    self.t.bind('<Drag-recieve>', self.OnDrag)
    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:

    class Treectrl(tkinter.Widget):

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.

Need Your Help

Access the model in production.rb rails 3

ruby-on-rails ruby-on-rails-3

I have a model called SystemSettings with a name on and a value. It is where I store the majority of my configuration for my app. I need to be able to access it in my production.rb inside my rails ...

How to install Tridion Default Templates with Template Builder?


I want to install the Tridion 2011 Default Templates using the Template Builder. I select Tools, Create Default Building Blocks, chose the folder, and select OK. I have tried this on the server and