| 1 | title = 'Pmw.PromptDialog 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 | # This may demonstrate a bug in Tk. Click on Cancel in the confirm |
| 11 | # dialog and then click on OK in the password dialog. Under Solaris |
| 12 | # 2.5 and python 1.5, the Cancel button in the confirm dialog is still |
| 13 | # displayed active, that is, it has a lighter background. |
| 14 | |
| 15 | class Demo: |
| 16 | def __init__(self, parent): |
| 17 | # Create the dialog to prompt for the password. |
| 18 | self.dialog = Pmw.PromptDialog(parent, |
| 19 | title = 'Password', |
| 20 | label_text = 'Password:', |
| 21 | entryfield_labelpos = 'n', |
| 22 | entry_show = '*', |
| 23 | defaultbutton = 0, |
| 24 | buttons = ('OK', 'Cancel'), |
| 25 | command = self.execute) |
| 26 | self.dialog.withdraw() |
| 27 | |
| 28 | # Create the confirmation dialog. |
| 29 | self.confirm = Pmw.MessageDialog( |
| 30 | title = 'Are you sure?', |
| 31 | message_text = 'Are you really sure?', |
| 32 | defaultbutton = 0, |
| 33 | buttons = ('OK', 'Cancel')) |
| 34 | self.confirm.withdraw() |
| 35 | |
| 36 | # Create button to launch the dialog. |
| 37 | w = Tkinter.Button(parent, text = 'Show prompt dialog', |
| 38 | command = self.dialog.activate) |
| 39 | w.pack(padx = 8, pady = 8) |
| 40 | |
| 41 | def execute(self, result): |
| 42 | if result is None or result == 'Cancel': |
| 43 | print 'Password prompt cancelled' |
| 44 | self.dialog.deactivate(result) |
| 45 | else: |
| 46 | result = self.confirm.activate() |
| 47 | if result == 'OK': |
| 48 | print 'Password entered ' + self.dialog.get() |
| 49 | self.dialog.deactivate() |
| 50 | |
| 51 | ###################################################################### |
| 52 | |
| 53 | # Create demo in root window for testing. |
| 54 | if __name__ == '__main__': |
| 55 | root = Tkinter.Tk() |
| 56 | Pmw.initialise(root) |
| 57 | root.title(title) |
| 58 | |
| 59 | exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy) |
| 60 | exitButton.pack(side = 'bottom') |
| 61 | widget = Demo(root) |
| 62 | root.mainloop() |