/Tests/03-label.py
Python | 65 lines | 42 code | 9 blank | 14 comment | 2 complexity | 5b0a5acde1ea61c4f33bfa0dda73e741 MD5 | raw file
- from GUI import Window, Label, Font, application
- from GUI.StdColors import red
- from GUI.StdFonts import system_font
- num_rows = 6
- italic_font = Font("Times", 2 * system_font.size, ['italic'])
- #def dump_font(caption, f):
- # print caption, f.info()
- #
- #dump_font("System font:", system_font)
- #dump_font("Italic font:", italic_font)
- def make_label(text, **kwds):
- #print "Creating label", text
- return Label(text = text, **kwds)
- #print "Creating labels"
- lbls = [
- make_label("ParrotState:"),
- make_label("Resting"),
- make_label("Spam!\nGlorious Spam!"),
- make_label("Red", color = red),
- make_label("Big Italic", font = italic_font),
- make_label("Pig in the\nMiddle", just = 'center', width = 140),
- make_label("Right\nJustified", just = 'right', width = 140),
- ]
- #print "Setting label positions"
- #print "Setting lbls[0].position to (20, 20)"
- #print "Before: lbls[0].bounds =", lbls[0].bounds
- lbls[0].position = (20, 20)
- #print "After: lbls[0].bounds =", lbls[0].bounds
- lbls[1].position = (lbls[0].right, lbls[0].top)
- for i in range(2, len(lbls)):
- lbls[i].position = (lbls[0].left, lbls[i-1].bottom + 20)
- #for lbl in lbls:
- # print lbl.height
- #print "Creating window"
- win = Window(title = "Labels")
- for lbl in lbls:
- win.add(lbl)
- win.size = (lbls[-1].right + 20, lbls[-1].bottom + 20)
- win.show()
- instructions = """
- There should be six rows of labels:
- 1. Two labels "ParrotState:" and "Resting", abutting but not overlapping.
- 2. A two-line label "Spam!\\nGlorious Spam!"
- 3. A label "Red" in red text.
- 4. A label "Big Italic" in a large italic font.
- 5. A two-line label "Pig in the\\nMiddle" centred in the window.
- 6. A two-line label "Right\\nJustified" right-aligned.
- All labels should remain stationary relative to the top left corner
- of the window when it is resized.
- """
- print instructions
- #application().menus = []
- application().run()