Создаёт многоколоночный список с заголовками. Колонки настраиваемой ширины. Пример встроен в скрипт.
from Tkinter import * import time
def fill():
- for i in range(1000):
- time.sleep(0.1) mlb.insert(END, ('Important Message: %d' % i, 'John Doe', '10/10/%04d' % (1900+i))) mlb.pack(expand=YES,fill=BOTH) tk.update_idletasks()
class MultiListbox(Frame):
def init(self, master, lists):
Frame.init(self, master) self.lists = [] for l,w in lists:
- frame = Frame(self); frame.pack(side=LEFT, expand=YES, fill=BOTH) Label(frame, text=l, borderwidth=1, relief=RAISED).pack(fill=X) lb = Listbox(frame, width=w, borderwidth=0, selectborderwidth=0,
- relief=FLAT, exportselection=FALSE)
lb.bind('<B1-Motion>', lambda e, s=self: s._select(e.y)) lb.bind('<Button-1>', lambda e, s=self: s._select(e.y)) lb.bind('<Leave>', lambda e: 'break') lb.bind('<B2-Motion>', lambda e, s=self: s._b2motion(e.x, e.y)) lb.bind('<Button-2>', lambda e, s=self: s._button2(e.x, e.y))
- frame = Frame(self); frame.pack(side=LEFT, expand=YES, fill=BOTH) Label(frame, text=l, borderwidth=1, relief=RAISED).pack(fill=X) lb = Listbox(frame, width=w, borderwidth=0, selectborderwidth=0,
- row = self.lists[0].nearest(y) self.selection_clear(0, END) self.selection_set(row) return 'break'
- for l in self.lists: l.scan_mark(x, y) return 'break'
- for l in self.lists: l.scan_dragto(x, y) return 'break'
- for l in self.lists:
- apply(l.yview, args)
- return self.lists[0].curselection()
- for l in self.lists:
- l.delete(first, last)
- result = [] for l in self.lists:
- result.append(l.get(first,last))
- self.lists[0].index(index)
- for e in elements:
- i = 0 for l in self.lists:
- l.insert(index, e[i]) i = i + 1
- l.see(END)
- i = 0 for l in self.lists:
- return self.lists[0].size()
- for l in self.lists:
- l.see(index)
- for l in self.lists:
- l.selection_anchor(index)
- for l in self.lists:
- l.selection_clear(first, last)
- return self.lists[0].selection_includes(index)
- for l in self.lists:
- l.selection_set(first, last)
if name == 'main':
- tk = Tk() Button(text='Заполнить',command=fill).pack()
Label(tk, text='MultiListbox').pack() mlb = MultiListbox(tk, (('Subject', 40), ('Sender', 20), ('Date', 10))) tk.mainloop()
}}}
