File: PromptDialog.py

package info (click to toggle)
python-pmw 0.6.2-0.1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 1,652 kB
  • ctags: 2,716
  • sloc: python: 10,720; makefile: 44; sh: 24
file content (58 lines) | stat: -rw-r--r-- 1,627 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
""" Demonstration of the Pmw PromptDialog megawidget.
"""

# Import Pmw from the sibling directory.
import sys
sys.path[:0] = ['../../..']

import Tkinter
import Pmw

class Demo:
    def __init__(self, parent):
	# Create the dialog to prompt for the password.
	self.dialog = Pmw.PromptDialog(parent,
	    title = 'Password',
	    label_text = 'Password:',
	    entryfield_labelpos = 'n',
	    entry_show = '*',
	    defaultbutton = 0,
	    buttons = ('OK', 'Cancel'),
	    command = self.execute)
	self.dialog.withdraw()

	# Create the confirmation dialog.
	self.confirm = Pmw.MessageDialog(
	    title = 'Are you sure?',
	    message_text = 'Are you really sure?',
	    defaultbutton = 0,
	    buttons = ('OK', 'Cancel'))
	self.confirm.withdraw()

	# Create button to launch the dialog.
	w = Tkinter.Button(parent, text = 'Show prompt dialog',
	        command = self.dialog.activate)
	w.pack(padx = 8, pady = 8)

    def execute(self, result):
	if result is None or result == 'Cancel':
	    print 'Password prompt cancelled'
	    self.dialog.deactivate(result)
	else:
	    result = self.confirm.activate()
	    if result == 'OK':
		print 'Password entered ' + self.dialog.get()
		self.dialog.deactivate()

######################################################################

# Create demo in root window for testing.
if __name__ == '__main__':
    root = Tkinter.Tk()
    Pmw.initialise(root, fontScheme = 'pmw1')
    root.title('Pmw PromptDialog demonstration')

    exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
    exitButton.pack(side = 'bottom')
    widget = Demo(root)
    root.mainloop()