Discussion:
[Tkinter-discuss] Notebook - Bad Window Path Name
Mario St-Gelais
2011-03-19 15:58:16 UTC
Permalink
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.

Thanks.

Code is:

from tkinter import *
from tkinter import ttk

class ClientNoteBook():
def __init__(self, root):
self.root=root
nb=ttk.Notebook(root)
f1=Frame(nb)
f2=FirstFrame(nb)
nb.add(f1, text='info')
nb.add(f2, text='in')
nb.pack()
def PlaceClientInfo(self):
pass

class FirstFrame():
def __init__(self,root):
self.root=root
self.frame=Frame(self.root)
self.PlaceButtonCheck()
def PlaceButtonCheck(self):
self.btn=ttk.Button(self.root,text='Open
Child',command=self.DebugThis) self.btn.grid(column=0,row=1)
def DebugThis(self):
print('rrrrrr')

if __name__=='__main__':
root = Tk()
root.option_add('*font', ('verdana', 9, 'normal'))
root.title("Information Client")
display = ClientNoteBook(root)
root.mainloop()

Error returned is:

Traceback (most recent call last):
File "/tmp/clientnotebook.py", line 31, in <module>
display = ClientNoteBook(root)
File "/tmp/clientnotebook.py", line 11, in __init__
nb.add(f2, text='in')
File "/usr/lib/python3.2/tkinter/ttk.py", line 865, in add
self.tk.call(self._w, "add", child, *(_format_optdict(kw)))
_tkinter.TclError: bad window path name "<__main__.FirstFrame object at
0x7f556e74dcd0>"
Michael Lange
2011-03-19 17:37:07 UTC
Permalink
Hi Mario,

Thus spoketh Mario St-Gelais <mario.stg at videotron.ca>
Post by Mario St-Gelais
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.
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
Mario St-Gelais
2011-03-20 12:45:33 UTC
Permalink
Thanks. This is an answer on a silver plate. :)
Thanks for the self.root tip too.

That definitely did the trick. I went with your option two.

Mario

On Sat, 19 Mar 2011 18:37:07 +0100
Post by Michael Lange
Hi Mario,
Thus spoketh Mario St-Gelais <mario.stg at videotron.ca>
Post by Mario St-Gelais
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.
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
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
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
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss at python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss
Loading...