statusbar.py 1.4 KB

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