Trouble running a Grayson Example
Robert Roy
rjroy at takingcontrol.com
Mon Mar 5 20:46:45 EST 2001
On Mon, 05 Mar 2001 19:13:50 GMT, David Lees
<deblNonOspammy at theworld.com> wrote:
>I am trying to run example 8.9 (Example_8_9.py) from Graysons book,
>under Python 2.0 and get the following errors. Can someone tell me what
>is going on? Perhaps this has to do with changes between 1.5.2 and 2.0
>Python?
>
>Thanks in advance.
>
>david lees
>
>
>Traceback (most recent call last): File
>"d:\Python20\Pythonwin\pywin\framework\scriptutils.py", line 301, in
>RunScript
> exec codeObject in __main__.__dict__
> File "E:\Grayson1\Chapter08\Example_8_9.py", line 79, in ?
> ddnotebook = DDNotebook()
> File "E:\Grayson1\Chapter08\AppShell.py", line 55, in __init__
> self.__createInterface()
> File "E:\Grayson1\Chapter08\AppShell.py", line 282, in
>__createInterface
> self.createInterface()
> File "E:\Grayson1\Chapter08\Example_8_9.py", line 75, in
>createInterface
> self.createNotebook()
> File "E:\Grayson1\Chapter08\Example_8_9.py", line 26, in
>createNotebook Pmw.NoteBookR,(self.interior(),),)
> File "E:\Downloads\pmw\Pmw\Pmw_0_8_4\lib\PmwLoader.py", line 174, in
>__getattr__
>AttributeError: NoteBookR
The examples in the Grayson book were written using an older version
of Pmw probably 0_8_1. NoteBookR ceased to exist in 0_8_3 and you are
using 0_8_4. There were some fundamentat changes to the way Notebook
works.
The following code will work.
def createNotebook(self):
# changed Pmw.NoteBookR to Pmw.NoteBook
self.notebook = self.createcomponent('notebook', (), None,
Pmw.NoteBook,
(self.interior(),),)
self.notebook.pack(side=TOP, expand=YES, fill=BOTH, padx=5,
pady=5)
self.formwidth = self.root.winfo_width()
def addPage(self, dictionary):
table, top, anchor, incr, fields, \
title, keylist = dataDict[dictionary]
# there is no label attribute anymore but a tab_text attribute
#(optional)
# self.notebook.add(table,label=title)
self.notebook.add(table, tab_text=title)
self.current = 0
ypos = top
idx = 0
for label, field, width, proc, valid, nonblank in fields:
pstr = 'Label(self.notebook.page(table),'\
'text="%s").place(relx=%f,rely=%f, anchor=E)\n' % \
(label, (anchor-0.02), ypos)
if idx == keylist[0]:
# self.notebook.page(table).interior() to self.notebook.page(table)
# did this in 3 places
pstr = '%sself.%s=Entry(self.notebook.page(table),'\
'text="",insertbackground="yellow",
width=%d+1,'\
'highlightthickness=1)\n' % (pstr,field,width)
else:
pstr = '%sself.%s=Entry(self.notebook.page(table),'\
'text="", insertbackground="yellow",'\
'width=%d+1)\n' % (pstr,field,width)
pstr = '%sself.%s.place(relx=%f, rely=%f,'\
'anchor=W)\n' % (pstr,field,(anchor+0.02),ypos)
exec '%sself.%sV=StringVar()\n'\
'self.%s["textvariable"] = self.%sV' % \
(pstr,field,field,field)
ypos = ypos + incr
idx = idx + 1
More information about the Python-list
mailing list