File: NoteBookR.py

package info (click to toggle)
python-pmw 0.8.1-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,972 kB
  • ctags: 3,391
  • sloc: python: 13,563; makefile: 44; sh: 24
file content (62 lines) | stat: -rw-r--r-- 1,647 bytes parent folder | download
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
59
60
61
62
""" Demonstration of the Pmw NoteBook megawidget.
"""

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

import Tkinter
import Pmw

class Demo:
    def __init__(self, parent):

        # Create the NoteBook.
	nb = Pmw.NoteBookR(parent)
	nb.add('hello', label='Hello')
	nb.add('world', label='World')
	nb.add('bye', label='Bye now!')

	# Fill in some pages
	self.makeHelloPage( nb.page('hello').interior() )
	self.makeWorldPage( nb.page('world').interior() )
	self.makeByePage( nb.page('bye').interior() )

	nb.pack(padx = 5, pady = 5, fill = 'both', expand = 1)

    def makeHelloPage(self,page):
	l = Tkinter.Button(page,text='Hello,...',fg='red')
	l.pack()

    def makeWorldPage(self,page):
	l = Tkinter.Canvas(page,background='black')
	w = l.winfo_reqwidth()
	h = l.winfo_reqheight()
	l.create_oval(10,10,w-10,h-10,fill='blue')
	l.create_text(
	    w/2,h/2,text='World!', fill='white',
	    font='-*-fixed-bold-*-*-*-24-*-*-*-*-*-iso8859-*'
	    )
	l.pack(fill = 'both', expand = 1) 

    def makeByePage(self,page):
	l = Tkinter.Text(page,width=40,height=10)
	l.tag_configure('foo',justify='center')
	l.insert('end','Goodbye, cruel world!')
	l.tag_add('foo','0.0','end')
	l.pack(fill = 'both', expand = 1) 

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

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

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