Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | title = 'Pmw.ScrolledField demonstration' |
2 | ||
3 | # Import Pmw from this directory tree. | |
4 | import sys | |
5 | sys.path[:0] = ['../../..'] | |
6 | ||
7 | import Tkinter | |
8 | import Pmw | |
9 | ||
10 | class Demo: | |
11 | def __init__(self, parent): | |
12 | # Create and pack the ScrolledField. | |
13 | self._field = Pmw.ScrolledField(parent, entry_width = 30, | |
14 | entry_relief='groove', labelpos = 'n', | |
15 | label_text = 'Scroll the field using the\nmiddle mouse button') | |
16 | self._field.pack(fill = 'x', expand = 1, padx = 10, pady = 10) | |
17 | ||
18 | # Create and pack a button to change the ScrolledField. | |
19 | self._button = Tkinter.Button(parent, text = 'Change field', | |
20 | command = self.execute) | |
21 | self._button.pack(padx = 10, pady = 10) | |
22 | ||
23 | self._index = 0 | |
24 | self.execute() | |
25 | ||
26 | def execute(self): | |
27 | self._field.configure(text = lines[self._index % len(lines)]) | |
28 | self._index = self._index + 1 | |
29 | ||
30 | lines = ( | |
31 | 'Alice was beginning to get very tired of sitting by her sister', | |
32 | 'on the bank, and of having nothing to do: once or twice she had', | |
33 | 'peeped into the book her sister was reading, but it had no', | |
34 | 'pictures or conversations in it, "and what is the use of a book,"', | |
35 | 'thought Alice "without pictures or conversation?"', | |
36 | 'Alice\'s Adventures in Wonderland', | |
37 | 'Lewis Carroll', | |
38 | ) | |
39 | ||
40 | ###################################################################### | |
41 | ||
42 | # Create demo in root window for testing. | |
43 | if __name__ == '__main__': | |
44 | root = Tkinter.Tk() | |
45 | Pmw.initialise(root) | |
46 | root.title(title) | |
47 | ||
48 | exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy) | |
49 | exitButton.pack(side = 'bottom') | |
50 | widget = Demo(root) | |
51 | root.mainloop() |