Skip to content

Commit 1b87c6c

Browse files
author
Mofan Zhou
committedJun 13, 2016
create tk4
1 parent f99767c commit 1b87c6c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
 

‎tkinterTUT/tk4_listbox.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import tkinter as tk
2+
3+
window = tk.Tk()
4+
window.title('my window')
5+
window.geometry('200x200')
6+
7+
var1 = tk.StringVar()
8+
l = tk.Label(window, bg='yellow', width=4, textvariable=var1)
9+
l.pack()
10+
11+
def print_selection():
12+
value = lb.get(lb.curselection())
13+
var1.set(value)
14+
15+
b1 = tk.Button(window, text='print selection', width=15,
16+
height=2, command=print_selection)
17+
b1.pack()
18+
19+
var2 = tk.StringVar()
20+
var2.set((11,22,33,44))
21+
lb = tk.Listbox(window, listvariable=var2)
22+
list_items = [1,2,3,4]
23+
for item in list_items:
24+
lb.insert('end', item)
25+
lb.insert(1, 'first')
26+
lb.insert(2, 'second')
27+
lb.delete(2)
28+
lb.pack()
29+
30+
window.mainloop()

0 commit comments

Comments
 (0)
Please sign in to comment.