SHARE
TWEET

Rob's MultiListbox (in progress)

bluegator4 May 3rd, 2014 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from tkinter import *
  2.  
  3. class MlbColumn(Frame):
  4.     def __init__(self, master, name, width):
  5.         Frame.__init__(self, master)
  6.         self.name = name
  7.         self.width = width
  8.         lb_frame = Frame(self)
  9.         lb_name = Label(lb_frame, text=self.name, borderwidth=1, relief=RAISED)
  10.         self.lb = Listbox(lb_frame, selectmode=SINGLE, width=self.width)
  11.         self.lb_footer = Label(lb_frame, borderwidth=1, relief=RAISED)
  12.  
  13.         lb_frame.grid(sticky=E+W)
  14.         lb_name.grid(row=0, column=0, sticky = E+W)
  15.         self.lb.grid(row=1, column=0,sticky = E+W)
  16.         self.lb_footer.grid(row=2,column=0,sticky = E+W)
  17.         self.lb.bind('<Button-1>',lambda e: print(self.SelectedItem(e.y)))
  18.  
  19.     def InsertList(self,data):
  20.         for item in data:
  21.             self.lb.insert(END,item)
  22.  
  23.     def InsertRow(self,row):
  24.         self.lb.insert(END,row)
  25.  
  26.     def ClearData(self):
  27.         self.lb.delete(0,END)
  28.  
  29.     def SelectedItem(self,y):
  30.         # Index number of selected item
  31.         return self.lb.nearest(y)
  32.  
  33.     def SelectItem(self, index):
  34.         # Select the item at the selected index number
  35.         self.lb.selection_clear(0,END)
  36.         self.lb.selection_set(index)
  37.  
  38.     def FooterText(self,text):
  39.         self.lb_footer.config(text=text)
  40.  
  41. columns = (("First",15),("Last",15))
  42. listboxes = []
  43.  
  44. master = Tk()
  45. mlb_frame = Frame(master)
  46. mlb_frame.grid()
  47. col_num = 0
  48. for name, width in columns:
  49.     lb = MlbColumn(mlb_frame,name,width)
  50.     lb.grid(row=0,column=col_num,sticky=E+W)
  51.     listboxes.append(lb)
  52.     col_num = col_num + 1
  53.  
  54. fullnames =[('Tony','Fernandez'),('Bryan','Galicia'),('Kevin','Galicia'),('Ricardo','Metayer'),('Victor','Gonzalez'),
  55.             ('Matt','Pompa'),('Dave','Schoeff'),('Leon','Heaven'),('Sergio','Pineda')]
  56.  
  57. for name in range(0,len(fullnames)):
  58.     for field in range(0,len(fullnames[name])):
  59.         listboxes[field].InsertRow(fullnames[name][field])
  60.  
  61.  
  62.  
  63. # lb.InsertData(data)
  64. # lb.FooterText('footsie')
  65. master.mainloop()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top