Skip to content

Commit 1cb0c16

Browse files
committed
tkinter
1 parent b6227a0 commit 1cb0c16

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# author: Bartlomiej "furas" Burek (https://blog.furas.pl)
2+
# date: 2022.03.11
3+
4+
import tkinter as tk
5+
6+
class ScrolledListbox(tk.Frame):
7+
8+
def __init__(self, *args, **kwargs):
9+
super().__init__(*args, **kwargs)
10+
11+
self.listbox = tk.Listbox(self)
12+
self.listbox.pack(side='left', fill='both', expand=True)
13+
14+
self.scrollbar = tk.Scrollbar(self, orient='vertical', command=self.listbox.yview)
15+
self.scrollbar.pack(side='right', fill='y')
16+
#self.scrollbar.pack(side='left', fill='y') # `left` also works
17+
18+
self.listbox.config(yscrollcommand=self.scrollbar.set)
19+
20+
# - main -
21+
22+
root = tk.Tk()
23+
24+
# - create -
25+
26+
lb1 = ScrolledListbox(root)
27+
lb1.pack(side='left', fill='both', expand=True)
28+
29+
lb2 = ScrolledListbox(root)
30+
lb2.pack(side='left', fill='both', expand=True)
31+
32+
lb3 = ScrolledListbox(root)
33+
lb3.pack(side='left', fill='both', expand=True)
34+
35+
# - add some values to listbox for scrolling -
36+
37+
for i in range(50):
38+
lb1.listbox.insert('end', str(i))
39+
lb2.listbox.insert('end', str(i+100))
40+
lb3.listbox.insert('end', str(i+200))
41+
42+
# - start -
43+
44+
root.mainloop()
45+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# author: Bartlomiej "furas" Burek (https://blog.furas.pl)
2+
# date: 2022.03.11
3+
4+
import tkinter as tk
5+
6+
root = tk.Tk()
7+
8+
# - create -
9+
10+
listbox = tk.Listbox(root)
11+
listbox.pack(side='left', fill='both', expand=True)
12+
13+
scrollbar = tk.Scrollbar(root, orient='vertical', command=listbox.yview)
14+
scrollbar.pack(side='right', fill='y')
15+
#scrollbar.pack(side='left', fill='y') # `left` also works
16+
17+
listbox.config(yscrollcommand=scrollbar.set)
18+
19+
# - add some values to listbox for scrolling -
20+
21+
for i in range(50):
22+
listbox.insert('end', str(i))
23+
24+
# - start -
25+
26+
root.mainloop()
27+

0 commit comments

Comments
 (0)