Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- class MlbColumn(Frame):
- def __init__(self, master, name, width):
- Frame.__init__(self, master)
- self.name = name
- self.width = width
- lb_frame = Frame(self)
- lb_name = Label(lb_frame, text=self.name, borderwidth=1, relief=RAISED)
- self.lb = Listbox(lb_frame, selectmode=SINGLE, width=self.width)
- self.lb_footer = Label(lb_frame, borderwidth=1, relief=RAISED)
- lb_frame.grid(sticky=E+W)
- lb_name.grid(row=0, column=0, sticky = E+W)
- self.lb.grid(row=1, column=0,sticky = E+W)
- self.lb_footer.grid(row=2,column=0,sticky = E+W)
- self.lb.bind('<Button-1>',lambda e: print(self.SelectedItem(e.y)))
- def InsertList(self,data):
- for item in data:
- self.lb.insert(END,item)
- def InsertRow(self,row):
- self.lb.insert(END,row)
- def ClearData(self):
- self.lb.delete(0,END)
- def SelectedItem(self,y):
- # Index number of selected item
- return self.lb.nearest(y)
- def SelectItem(self, index):
- # Select the item at the selected index number
- self.lb.selection_clear(0,END)
- self.lb.selection_set(index)
- def FooterText(self,text):
- self.lb_footer.config(text=text)
- columns = (("First",15),("Last",15))
- listboxes = []
- master = Tk()
- mlb_frame = Frame(master)
- mlb_frame.grid()
- col_num = 0
- for name, width in columns:
- lb = MlbColumn(mlb_frame,name,width)
- lb.grid(row=0,column=col_num,sticky=E+W)
- listboxes.append(lb)
- col_num = col_num + 1
- fullnames =[('Tony','Fernandez'),('Bryan','Galicia'),('Kevin','Galicia'),('Ricardo','Metayer'),('Victor','Gonzalez'),
- ('Matt','Pompa'),('Dave','Schoeff'),('Leon','Heaven'),('Sergio','Pineda')]
- for name in range(0,len(fullnames)):
- for field in range(0,len(fullnames[name])):
- listboxes[field].InsertRow(fullnames[name][field])
- # lb.InsertData(data)
- # lb.FooterText('footsie')
- master.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement