[Tkinter-discuss] Python Tk Bwidget Tree problem with drag and drop

Olivier Feys olivier.feys at gmail.com
Sat Oct 15 16:36:50 CEST 2005


Thanks a lot Jeff, i think this is really going to help me.



On 05/10/05, jepler at unpythonic.net <jepler at unpythonic.net> wrote:
>
> I haven't used bwidget drag and drop myself.
>
> You can get the widget object for a string path by using
> bwidget.nametowidget
> but I had trouble with this since often the name of an internal widget,
> such as
> (in my case) '.1077785676.c', is returned. Perhaps by chopping off parts
> until
> a recognized widget is found will work.
>
> Here's a small program I just wrote which demonstrates drag&drop between
> two
> ListBox (not Tree) widgets.
>
> from Tkinter import *
> from bwidget import *
> import bwidget
>
> def nametowidget(name):
> while name:
> try:
> return bwidget.nametowidget(app, name)
> except KeyError:
> i = name.rindex('.')
> name = name[:i]
>
> def draginit(a, b, c): return ('LISTBOX_ITEM', 'move', b)
>
> def do_drop(src, dest, where, op, kind, data):
> src = nametowidget(src)
> dest = nametowidget(dest)
> src.insert(END, text=dest.itemcget(data, "text"))
>
> def do_drag(src, dest, op, kind, data, result):
> if result:
> src = nametowidget(src)
> src.delete(data)
>
> common_args = {'dropcmd': do_drop, 'dragendcmd': do_drag, 'dragenabled':
> 1,
> 'dropenabled': 1, 'dropovermode': 'w'}
>
> app = Tk()
>
> t = ListBox(app, **common_args)
> t.pack(side=LEFT)
> for text in "abcde":
> t.insert(END, text=text*3)
>
> u = ListBox(app, **common_args)
> u.pack(side=LEFT)
> for text in "12345":
> u.insert(END, text=text*3)
>
> app.mainloop()
>
>
> Jeff
>
>
>


--

Olivier Feys

Ringlaan 20
B-3080 Tervuren - BELGIUM
mailto:olivier.feys at gmail.com
Mobile phone : +32486/41.65.81
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20051015/31cdc21e/attachment.htm


More information about the Tkinter-discuss mailing list