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