Bonjour à tous,

Je recherche un moyen d'effectuer un drag and drop entre 2 treeview
Je trouve des tutos pour le faire à l’intérieur d’un treeview mais pas entre deux diffèrent





Merci d’avance


J'utilise ce code pour mes tests.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
 
from tkinter import *
from tkinter import ttk
 
def bDown_Shift(event):
    tv = event.widget
    select = [tv.index(s) for s in tv.selection()]
    select.append(tv.index(tv.identify_row(event.y)))
    select.sort()
    for i in range(select[0],select[-1]+1,1):
        tv.selection_add(tv.get_children()[i])
 
def bDown(event):
    tv = event.widget
 
    if tv.identify_row(event.y) not in tv.selection():
        tv.selection_set(tv.identify_row(event.y))
 
def bUp(event):
    tv = event.widget
    if tv.identify_row(event.y) in tv.selection():
        tv.selection_set(tv.identify_row(event.y))
 
def bUp_Shift(event):
    pass
 
def bMove(event):
    tv = event.widget
    print(tv)
    moveto = tv.index(tv.identify_row(event.y))
    for s in tv.selection():
        tv.move(s, '', moveto)
 
root = Tk()
 
tree = ttk.Treeview(columns=("col1","col2"),
                    displaycolumns="col2",
                    selectmode='none')
 
# insert some items into the tree
for i in range(10):
    tree.insert('', 'end',iid='line%i' % i, text='line:%s' % i, values=('', i))
 
tree2 = ttk.Treeview (columns=("col1", "col2"),
                     displaycolumns="col2",
                     selectmode='none')
 
# insert some items into the tree
for i in range (10) :
    tree2.insert ('', 'end', iid='line%i' % i, text='line:%s' % i, values=('', i))
 
 
 
 
 
tree.pack()
tree2.pack()
 
tree.bind("<ButtonPress-1>",bDown)
tree.bind("<ButtonRelease-1>",bUp, add='+')
tree.bind("<B1-Motion>",bMove, add='+')
 
tree.bind("<Shift-ButtonPress-1>",bDown_Shift, add='+')
tree.bind("<Shift-ButtonRelease-1>",bUp_Shift, add='+')
 
 
tree2.bind("<ButtonPress-1>",bDown)
tree2.bind("<ButtonRelease-1>",bUp, add='+')
tree2.bind("<B1-Motion>",bMove, add='+')
 
 
tree2.bind("<Shift-ButtonPress-1>",bDown_Shift, add='+')
tree2.bind("<Shift-ButtonRelease-1>",bUp_Shift, add='+')
 
 
 
root.mainloop()