Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_toggle_selection.py
- from Tkinter import *
- root = Tk()
- lb = Label(text="Tk Select Toggle Demo")
- lb.pack()
- mylist='abc def ghi jkl mno pqr stu vwx 123 456 789'.split()
- def select_chk():
- vsel=lb.curselection()
- if len(vsel) == 0:
- lb.select_set(0, END)
- elif len(vsel) == 1:
- print "You can select more than one in this demo"
- print lb.get(int(vsel[0]))
- print
- else:
- lb.select_clear(0, END)
- def pr_chk():
- vsel=lb.curselection()
- for z in vsel:
- z=int(z)
- print lb.get(z)
- print
- #
- lsb_f = Frame(root)
- lsb_f.pack(side="top", padx=10)
- lb = Listbox(lsb_f, width=20, height=7, selectmode=MULTIPLE)
- scr = Scrollbar(lsb_f)
- scr["command"] = lb.yview
- lb["yscrollcommand"] = scr.set
- lb.pack(side="left", pady=5)
- scr.pack(side="right", pady=5, fill="y")
- for z in mylist: lb.insert(END, z)
- lb.pack()
- Button(root, text='Toggle Selection', command=select_chk).pack(side=LEFT)
- Button(root, text='Screen Print Selection', command=pr_chk).pack(side=LEFT)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement