1 title = 'Using Tk option database to configure Pmw megawidgets'
3 # Import Pmw from this directory tree.
5 sys.path[:0] = ['../../..']
11 def __init__(self, parent):
14 header = Tkinter.Label(parent, text = 'Select some Tk option ' +
15 'database values from\nthe lists, then click ' +
16 '\'Create dialog\' to create\na MessageDialog with ' +
17 'these values as defaults.')
18 header.pack(padx = 10, pady = 10)
20 # Create and pack the ComboBoxes to select options.
25 "('OK', 'Apply', 'Cancel', 'Help')",
28 if Tkinter.TkVersion >= 8.4:
29 disabledState = 'readonly'
31 disabledState = 'disabled'
33 self._buttons = Pmw.ComboBox(parent, label_text = 'buttons:',
35 entry_state = disabledState,
36 scrolledlist_items = buttons)
37 self._buttons.pack(fill = 'x', expand = 1, padx = 8, pady = 8)
38 self._buttons.selectitem(3)
40 buttonboxpos = ('n', 's', 'e', 'w',)
41 self._buttonboxpos = Pmw.ComboBox(parent, label_text = 'buttonboxpos:',
43 entry_state = disabledState,
44 scrolledlist_items = buttonboxpos)
45 self._buttonboxpos.pack(fill = 'x', expand = 1, padx = 8, pady = 8)
46 self._buttonboxpos.selectitem(2)
48 pad = ('0', '8', '20', '50',)
49 self._pad = Pmw.ComboBox(parent, label_text = 'padx, pady:',
51 entry_state = disabledState,
52 scrolledlist_items = pad)
53 self._pad.pack(fill = 'x', expand = 1, padx = 8, pady = 8)
54 self._pad.selectitem(1)
56 Pmw.alignlabels((self._buttons, self._buttonboxpos, self._pad))
58 # Create button to launch the dialog.
59 w = Tkinter.Button(parent, text = 'Create dialog',
60 command = self._createDialog)
61 w.pack(padx = 8, pady = 8)
65 def _createDialog(self):
67 # Set the option database.
68 buttons = self._buttons.get()
69 buttonboxpos = self._buttonboxpos.get()
71 self.parent.option_add('*MessageDialog.buttons', buttons)
72 self.parent.option_add('*MessageDialog.buttonboxpos', buttonboxpos)
73 self.parent.option_add('*ButtonBox.padx', pad)
74 self.parent.option_add('*ButtonBox.pady', pad)
77 if self.dialog is not None:
80 text = ('This dialog was created by setting the Tk ' +
81 'option database:\n\n *MessageDialog.buttons: ' + buttons +
82 '\n *MessageDialog.buttonboxpos: ' + buttonboxpos +
83 '\n *ButtonBox.padx: ' + pad +
84 '\n *ButtonBox.pady: ' + pad)
85 self.dialog = Pmw.MessageDialog(self.parent,
87 title = 'Pmw option database demonstration',
88 message_justify = 'left',
90 self.dialog.iconname('Test dialog')
92 # Return the defaults to normal, otherwise all other demos
94 self.parent.option_add('*MessageDialog.buttons', "('OK',)")
95 self.parent.option_add('*MessageDialog.buttonboxpos', 's')
96 self.parent.option_add('*ButtonBox.padx', 8)
97 self.parent.option_add('*ButtonBox.pady', 8)
99 ######################################################################
101 # Create demo in root window for testing.
102 if __name__ == '__main__':
104 Pmw.initialise(root, useTkOptionDb = 1)
107 exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
108 exitButton.pack(side = 'bottom')