[Tkinter-discuss] Notebook - Bad Window Path Name

Michael Lange klappnase at web.de
Sat Mar 19 18:37:07 CET 2011


Hi Mario,

Thus spoketh Mario St-Gelais <mario.stg at videotron.ca> 
unto us on Sat, 19 Mar 2011 11:58:16 -0400:

> Good Day All.
> 
> I am trying to get Notebook to work and the following code return
> errors.  If I replace f2 with something similar to f1, it works.
> 

The problem is the following class definition:

> 
> class FirstFrame():
>     def __init__(self,root):
>         self.root=root
>         self.frame=Frame(self.root)
>         self.PlaceButtonCheck()
(...)

According to this, an instance of the FirstFrame class is *not* a tk
widget, but just a generic python object. So you will have to 

* either replace the following lines in your code:

        f2=FirstFrame(nb)
        nb.add(f2, text='in')

  with

        f2=FirstFrame(nb)
        nb.add(f2.frame, text='in')# pass the Frame object to nb.add()

* or (better) change your class definition so that the FirstFrame
  instance becomes a real Frame object by subclassing Frame. The usual way
  to do this is something like:

class FirstFrame(Frame):
    def __init__(self, *args, **kw):
        Frame.__init__(self, *args, **kw)
        self.PlaceButtonCheck()
    ...(etc.)...

(note that you don't need the self.root attribute any longer, because
every widget has its parent linked to self.master by default).

I hope this helps

Michael

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

I'm frequently appalled by the low regard you Earthmen have for life.
		-- Spock, "The Galileo Seven", stardate 2822.3


More information about the Tkinter-discuss mailing list