Guido van Rossum | 3b4ca0d | 1998-10-10 18:48:31 +0000 | [diff] [blame] | 1 | from Tkinter import * |
| 2 | |
| 3 | class Outline: |
| 4 | |
| 5 | def __init__(self, root=None): |
| 6 | if not root: |
| 7 | import Tkinter |
| 8 | root = Tkinter._default_root |
| 9 | if not root: |
| 10 | root = top = Tk() |
| 11 | else: |
| 12 | top = Toplevel(root) |
| 13 | top.wm_title("Outline") |
| 14 | self.canvas = canvas = Canvas(top, width=400, height=300, |
| 15 | borderwidth=2, relief="sunken", |
| 16 | background="#FFBBBB") |
| 17 | canvas.pack(expand=1, fill="both") |
| 18 | self.items = [] |
| 19 | |
| 20 | def additem(self, level, open, label): |
| 21 | x = 15*level + 5 |
| 22 | y = 15*len(self.items) + 5 |
| 23 | if open: |
| 24 | id1 = self.canvas.create_polygon(x+3, y+3, x+13, y+3, x+8, y+8, |
| 25 | outline="black", |
| 26 | fill="green") |
| 27 | else: |
| 28 | id1 = self.canvas.create_polygon(x+3, y+4, x+7, y+8, x+3, y+12, |
| 29 | outline="black", |
| 30 | fill="red") |
| 31 | w = Entry(self.canvas, borderwidth=0, background="#FFBBBB", width=0) |
| 32 | w.insert("end", label) |
| 33 | id2 = self.canvas.create_window(x+15, y, anchor="nw", window=w) |
| 34 | self.items.append((level, open, label, id1, w, id2)) |
| 35 | |
| 36 | |
| 37 | def main(): |
| 38 | o = Outline() |
| 39 | o.additem(0, 1, "hello world") |
| 40 | o.additem(1, 0, "sub1") |
| 41 | o.additem(1, 1, "sub2") |
| 42 | o.additem(2, 0, "sub2.a") |
| 43 | o.additem(2, 0, "sub2.b") |
| 44 | o.additem(1, 0, "sub3") |
| 45 | |
| 46 | main() |