1 title = 'Demonstration of how to create a megawidget'
3 # Import Pmw from this directory tree.
5 sys.path[:0] = ['../../..']
10 class TextDisplay(Pmw.MegaWidget):
12 # Demo Pmw megawidget.
14 def __init__(self, parent = None, **kw):
16 # Define the megawidget options.
18 self.defineoptions(kw, optiondefs)
20 # Initialise the base class (after defining the options).
21 Pmw.MegaWidget.__init__(self, parent)
23 # Create the components.
24 interior = self.interior()
26 self._text = self.createcomponent('text',
28 Tkinter.Text, (interior,), state = 'disabled')
29 self._text.pack(side='left', fill='both', expand='yes')
31 self._scrollbar = self.createcomponent('scrollbar',
33 Tkinter.Scrollbar, (interior,), command = self._text.yview)
34 self._scrollbar.pack(side='right', fill='y')
35 self._text.configure(yscrollcommand = self._scrollbar.set)
37 # Check keywords and initialise options.
38 self.initialiseoptions()
40 def display(self, info):
41 self._text.configure(state = 'normal')
42 self._text.delete('1.0', 'end')
43 self._text.insert('1.0', info)
44 self._text.configure(state = 'disabled')
46 def append(self, info):
47 self._text.configure(state = 'normal')
48 self._text.insert('end', info)
49 self._text.configure(state = 'disabled')
52 def __init__(self, parent):
53 # Create and pack the megawidget.
54 text = TextDisplay(parent,
55 text_background = 'aliceblue',
60 text.pack(fill = 'both', expand = 1)
61 text.display('This is an example of a simple Pmw megawidget.\n\n' +
62 'Public attributes of the Tkinter module:\n\n')
63 for name in dir(Tkinter):
65 text.append(' ' + name + '\n')
67 ######################################################################
69 # Create demo in root window for testing.
70 if __name__ == '__main__':
75 exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
76 exitButton.pack(side = 'bottom')