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

jepler@unpythonic.net jepler at unpythonic.net
Wed Oct 5 19:37:26 CEST 2005


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20051005/98b7abc8/attachment.pgp


More information about the Tkinter-discuss mailing list