Skip to content

Commit 009948a

Browse files
committed
tkinter
1 parent a6092cc commit 009948a

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
![#1](screenshots/image-1.png?raw=true)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
Loading

0 commit comments

Comments
 (0)