1 title = 'Pmw.ScrolledFrame demonstration'
3 # Import Pmw from this directory tree.
5 sys.path[:0] = ['../../..']
11 def __init__(self, parent):
12 # Create the ScrolledFrame.
13 self.sf = Pmw.ScrolledFrame(parent,
14 labelpos = 'n', label_text = 'ScrolledFrame',
20 # Create a group widget to contain the flex options.
21 w = Pmw.Group(parent, tag_text='Flex')
22 w.pack(side = 'bottom', padx = 5, pady = 3)
24 hflex = Pmw.OptionMenu(w.interior(),
26 label_text = 'Horizontal:',
27 items = ['fixed', 'expand', 'shrink', 'elastic'],
28 command = self.sethflex,
31 hflex.pack(side = 'left', padx = 5, pady = 3)
34 vflex = Pmw.OptionMenu(w.interior(),
36 label_text = 'Vertical:',
37 items = ['fixed', 'expand', 'shrink', 'elastic'],
38 command = self.setvflex,
41 vflex.pack(side = 'left', padx = 5, pady = 3)
44 # Create a group widget to contain the scrollmode options.
45 w = Pmw.Group(parent, tag_text='Scroll mode')
46 w.pack(side = 'bottom', padx = 5, pady = 0)
48 hmode = Pmw.OptionMenu(w.interior(),
50 label_text = 'Horizontal:',
51 items = ['none', 'static', 'dynamic'],
52 command = self.sethscrollmode,
55 hmode.pack(side = 'left', padx = 5, pady = 3)
56 hmode.invoke('dynamic')
58 vmode = Pmw.OptionMenu(w.interior(),
60 label_text = 'Vertical:',
61 items = ['none', 'static', 'dynamic'],
62 command = self.setvscrollmode,
65 vmode.pack(side = 'left', padx = 5, pady = 3)
66 vmode.invoke('dynamic')
68 self.radio = Pmw.RadioSelect(parent, selectmode = 'multiple',
69 command = self.radioSelected)
70 self.radio.add('center', text = 'Keep centered vertically')
71 self.radio.pack(side = 'bottom')
73 buttonBox = Pmw.ButtonBox(parent)
74 buttonBox.pack(side = 'bottom')
75 buttonBox.add('add', text = 'Add a button', command = self.addButton)
76 buttonBox.add('yview', text = 'Show yview', command = self.showYView)
77 buttonBox.add('scroll', text = 'Page down', command = self.pageDown)
79 # Pack this last so that the buttons do not get shrunk when
80 # the window is resized.
81 self.sf.pack(padx = 5, pady = 3, fill = 'both', expand = 1)
83 self.frame = self.sf.interior()
88 for count in range(15):
91 def sethscrollmode(self, tag):
92 self.sf.configure(hscrollmode = tag)
94 def setvscrollmode(self, tag):
95 self.sf.configure(vscrollmode = tag)
97 def sethflex(self, tag):
98 self.sf.configure(horizflex = tag)
100 def setvflex(self, tag):
101 self.sf.configure(vertflex = tag)
104 button = Tkinter.Button(self.frame,
105 text = '(%d,%d)' % (self.col, self.row))
106 button.grid(row = self.row, column = self.col, sticky = 'nsew')
108 self.frame.grid_rowconfigure(self.row, weight = 1)
109 self.frame.grid_columnconfigure(self.col, weight = 1)
110 if self.sf.cget('horizflex') == 'expand' or \
111 self.sf.cget('vertflex') == 'expand':
114 if 'center' in self.radio.getcurselection():
115 self.sf.update_idletasks()
118 if self.col == self.row:
120 self.row = self.row + 1
122 self.col = self.col + 1
125 print self.sf.yview()
128 self.sf.yview('scroll', 1, 'page')
130 def radioSelected(self, name, state):
134 def centerPage(self):
135 # Example of how to use the yview() method of Pmw.ScrolledFrame.
136 top, bottom = self.sf.yview()
138 middle = 0.5 - size / 2
139 self.sf.yview('moveto', middle)
141 ######################################################################
143 # Create demo in root window for testing.
144 if __name__ == '__main__':
151 Pmw.initialise(root, size = size, fontScheme = 'pmw2')
154 exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
155 exitButton.pack(side = 'bottom')