1from Tkinter import * 2 3class MultiStatusBar(Frame): 4 5 def __init__(self, master=None, **kw): 6 if master is None: 7 master = Tk() 8 Frame.__init__(self, master, **kw) 9 self.labels = {} 10 11 def set_label(self, name, text='', side=LEFT, width=0): 12 if name not in self.labels: 13 label = Label(self, borderwidth=0, anchor=W) 14 label.pack(side=side, pady=0, padx=4) 15 self.labels[name] = label 16 else: 17 label = self.labels[name] 18 if width != 0: 19 label.config(width=width) 20 label.config(text=text) 21 22def _multistatus_bar(parent): 23 root = Tk() 24 width, height, x, y = list(map(int, re.split('[x+]', parent.geometry()))) 25 root.geometry("+%d+%d" %(x, y + 150)) 26 root.title("Test multistatus bar") 27 frame = Frame(root) 28 text = Text(frame) 29 text.pack() 30 msb = MultiStatusBar(frame) 31 msb.set_label("one", "hello") 32 msb.set_label("two", "world") 33 msb.pack(side=BOTTOM, fill=X) 34 35 def change(): 36 msb.set_label("one", "foo") 37 msb.set_label("two", "bar") 38 39 button = Button(root, text="Update status", command=change) 40 button.pack(side=BOTTOM) 41 frame.pack() 42 frame.mainloop() 43 root.mainloop() 44 45if __name__ == '__main__': 46 from idlelib.idle_test.htest import run 47 run(_multistatus_bar) 48