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