File tree 4 files changed +57
-0
lines changed
drag-and-drop-files-from-system
treeview/treeview-scrollbar
4 files changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ # author: Bartlomiej "furas" Burek (https://blog.furas.pl)
2
+ # date: 2022.06.26
3
+
4
+ import tkinter as tk
5
+ from tkinterdnd2 import DND_FILES , TkinterDnD
6
+
7
+ def drop (event ):
8
+ text = event .data
9
+ text = text [1 :- 1 ] # remove first and last `{ }`
10
+ for item in text .split ('} {' ):
11
+ print (item )
12
+ print ('---' )
13
+ lb .insert ('end' , item )
14
+
15
+ # --- main ---
16
+
17
+ root = TkinterDnD .Tk ()
18
+
19
+ lb = tk .Listbox (root )
20
+ lb .pack (fill = 'both' , expand = True )
21
+
22
+ lb .insert (1 , "drag files to here" )
23
+
24
+ # register the listbox as a drop target
25
+ lb .drop_target_register (DND_FILES )
26
+ lb .dnd_bind ('<<Drop>>' , drop )
27
+
28
+ root .mainloop ()
29
+
Original file line number Diff line number Diff line change
1
+
2
+ ![ #1 ] ( screenshots/image-1.png?raw=true )
Original file line number Diff line number Diff line change
1
+ # author: Bartlomiej "furas" Burek (https://blog.furas.pl)
2
+ # date: 2022.06.26
3
+
4
+ import tkinter as tk
5
+ from tkinter import ttk
6
+
7
+ root = tk .Tk ()
8
+
9
+ tree = ttk .Treeview (root , selectmode = "browse" )
10
+ tree .pack (side = 'left' , fill = 'both' , expand = True )
11
+
12
+ # `command=tree.yview` sends information from `scrollbar` to `treeview` when `scrollbar` is moved (and threeview is moved too)
13
+
14
+ scrollbar = tk .Scrollbar (root , orient = 'vertical' , command = tree .yview )
15
+ scrollbar .pack (side = 'right' , fill = 'y' )
16
+
17
+ # `yscrollcommand=scrollbar.set` sends information from `treeview` to `scrollbar`
18
+ # to change size of `scrollbar` when items are added/removed from treeview
19
+ # and to move `scrollbar` when `treeview` is scrolled with mouse wheel.
20
+ tree .config (yscrollcommand = scrollbar .set )
21
+
22
+ for x in range (1 , 21 ):
23
+ print (tree .insert ('' , 'end' , text = str (x )))
24
+
25
+ root .mainloop ()
26
+
You can’t perform that action at this time.
0 commit comments