1from tkinter.ttk import Label, Frame 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, Text 24 from tkinter.ttk import Frame, Button 25 top = Toplevel(parent) 26 x, y = map(int, parent.geometry().split('+')[1:]) 27 top.geometry("+%d+%d" %(x, y + 175)) 28 top.title("Test multistatus bar") 29 frame = Frame(top) 30 text = Text(frame, height=5, width=40) 31 text.pack() 32 msb = MultiStatusBar(frame) 33 msb.set_label("one", "hello") 34 msb.set_label("two", "world") 35 msb.pack(side='bottom', fill='x') 36 37 def change(): 38 msb.set_label("one", "foo") 39 msb.set_label("two", "bar") 40 41 button = Button(top, text="Update status", command=change) 42 button.pack(side='bottom') 43 frame.pack() 44 45if __name__ == '__main__': 46 from unittest import main 47 main('idlelib.idle_test.test_statusbar', verbosity=2, exit=False) 48 49 from idlelib.idle_test.htest import run 50 run(_multistatus_bar) 51