Advertisement
here2share

# Tk_toggle_selection.py

Jul 29th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. # Tk_toggle_selection.py
  2.  
  3. from Tkinter import *
  4.  
  5. root = Tk()
  6. lb = Label(text="Tk Select Toggle Demo")
  7. lb.pack()
  8.  
  9. mylist='abc def ghi jkl mno pqr stu vwx 123 456 789'.split()
  10.  
  11. def select_chk():
  12.     vsel=lb.curselection()
  13.     if len(vsel) == 0:
  14.         lb.select_set(0, END)
  15.     elif len(vsel) == 1:
  16.         print "You can select more than one in this demo"
  17.         print lb.get(int(vsel[0]))
  18.         print
  19.     else:
  20.         lb.select_clear(0, END)
  21. def pr_chk():
  22.     vsel=lb.curselection()
  23.     for z in vsel:
  24.         z=int(z)
  25.         print lb.get(z)
  26.     print
  27. #
  28. lsb_f = Frame(root)
  29. lsb_f.pack(side="top", padx=10)
  30. lb = Listbox(lsb_f, width=20, height=7, selectmode=MULTIPLE)
  31. scr = Scrollbar(lsb_f)
  32. scr["command"] = lb.yview
  33. lb["yscrollcommand"] = scr.set
  34. lb.pack(side="left", pady=5)
  35. scr.pack(side="right", pady=5, fill="y")
  36. for z in mylist: lb.insert(END, z)
  37. lb.pack()
  38. Button(root, text='Toggle Selection', command=select_chk).pack(side=LEFT)
  39. Button(root, text='Screen Print Selection', command=pr_chk).pack(side=LEFT)
  40.  
  41. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement