1 title = 'Pmw.ScrolledText demonstration'
3 # Import Pmw from this directory tree.
5 sys.path[:0] = ['../../..']
12 def __init__(self, parent):
13 # Create the ScrolledText.
14 self.st = Pmw.ScrolledText(parent,
17 label_text='ScrolledText.py',
26 # Create a group widget to contain the scrollmode options.
27 w = Pmw.Group(parent, tag_text='Scroll mode')
28 w.pack(side = 'bottom', padx = 5, pady = 5)
30 hmode = Pmw.OptionMenu(w.interior(),
32 label_text = 'Horizontal:',
33 items = ['none', 'static', 'dynamic'],
34 command = self.sethscrollmode,
37 hmode.pack(side = 'left', padx = 5, pady = 5)
38 hmode.invoke('dynamic')
40 vmode = Pmw.OptionMenu(w.interior(),
42 label_text = 'Vertical:',
43 items = ['none', 'static', 'dynamic'],
44 command = self.setvscrollmode,
47 vmode.pack(side = 'left', padx = 5, pady = 5)
48 vmode.invoke('dynamic')
50 buttonBox = Pmw.ButtonBox(parent)
51 buttonBox.pack(side = 'bottom')
52 buttonBox.add('yview', text = 'Show\nyview', command = self.showYView)
53 buttonBox.add('scroll', text = 'Page\ndown', command = self.pageDown)
54 buttonBox.add('center', text = 'Center', command = self.centerPage)
56 # Pack this last so that the buttons do not get shrunk when
57 # the window is resized.
58 self.st.pack(padx = 5, pady = 5, fill = 'both', expand = 1)
60 # Read this file into the text widget.
61 head, tail = os.path.split(sys.argv[0])
62 self.st.importfile(os.path.join(head,'ScrolledText.py'))
64 self.st.insert('end', '\nThis demonstrates how to\n' +
65 'add a window to a text widget: ')
66 counter = Pmw.Counter(self.st.component('text'),
67 entryfield_value = 9999)
68 self.st.window_create('end', window = counter)
70 def sethscrollmode(self, tag):
71 self.st.configure(hscrollmode = tag)
73 def setvscrollmode(self, tag):
74 self.st.configure(vscrollmode = tag)
80 self.st.yview('scroll', 1, 'page')
83 top, bottom = self.st.yview()
85 middle = 0.5 - size / 2
86 self.st.yview('moveto', middle)
88 ######################################################################
90 # Create demo in root window for testing.
91 if __name__ == '__main__':
96 exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
97 exitButton.pack(side = 'bottom')