#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    2
    Rep Power
    0

    Tkinter, Toplevel and grid


    Hi,
    I'm trying to use a grid in a secondary window and failing.

    Here is my code:
    Code:
    class TopLevelTest4:
        def NewWindow(self):
            self.root2 = Toplevel()
            self.grid = Frame(self.root1)
            self.grid.pack()
            self.canvas2 = Canvas(self.root2, width=200, height=200)
            self.canvas2.grid(in_=self.grid,row=0,column=0)
            self.canvas3 = Canvas(self.root2, width=200, height=200)
            self.canvas3.grid(in_=self.grid,row=0,column=1)
            self.root2.title("New Window")
            self.root2.mainloop()
        def __init__(self):
            self.root1 = Tk()
            self.canvas1 = Canvas(self.root1, width=400, height=200)
            self.canvas1.pack()
            self.menubar = Menu(self.root1)
            self.menubar.add_command(label="New Window",command=self.NewWindow)
            self.root1.config(menu=self.menubar)
            self.root1.title("TopLevelTest")
            self.root1.mainloop()
            
    TopLevelTest4()


    and I get the following error:


    Exception in Tkinter callback
    Traceback (most recent call last):
    File "C:\Python22\lib\lib-tk\Tkinter.py", line 1292, in __call__
    return apply(self.func, args)
    File "<source>", line 56, in NewWindow
    File "C:\Python22\lib\lib-tk\Tkinter.py", line 1684, in grid_configure
    self.tk.call(
    TclError: can't put .27548696.27645416 inside .27572536
    Script '<source>' returned exit code 0


    Any ideas as to how I can sucessfully do this?

    Thanks,
    -Kalev
    Last edited by KalevTait; December 8th, 2003 at 08:01 PM.
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    The problem could have something to do with not being able to use grid() and pack() together.. so use one or the other and it should work

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Posts
    2
    Rep Power
    0
    hmm...
    it seems to work fine as long as its using Tk() and not Toplevel()

    as in:

    Code:
    class TopLevelTest3:
        def NewWindow(self):
            self.root2 = Toplevel()
            self.canvas3 = Canvas(self.root2, width=400, height=200)
            self.canvas3.pack()
            self.root2.title("New Window")
            self.root2.mainloop()
        def __init__(self):
            self.root1 = Tk()
            self.grid = Frame(self.root1)
            self.grid.pack()
            self.canvas1 = Canvas(self.root1, width=200, height=200)
            self.canvas1.grid(in_=self.grid,row=0,column=0)
            self.canvas2 = Canvas(self.root1, width=200, height=200)
            self.canvas2.grid(in_=self.grid,row=0,column=1)
            self.root1.title("TopLevelTest")
            self.menubar = Menu(self.root1)
            self.menubar.add_command(label="New Window",command=self.NewWindow)
            self.root1.config(menu=self.menubar)
            self.root1.mainloop()
    
    TopLevelTest3()


    But, I'll see what I can do without depending on both.

    Thanks,
    -Kalev
  6. #4
  7. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    Hi Kalev,

    If I understand it:
    Code:
    self.canvas2 = Canvas(self.root2, width=200, height=200)
    self.canvas2.grid(in_=self.grid,row=0,column=0)
    Here you create a canvas object as a child of self.root2 but when you apply it's grid method , self.grid is a child of self.root1 which is a frame in the first window you created.
    self.grid = Frame(self.root2)
    solves the problem.
    BTW I was confused by the use of grid as an object and method.

    Grim

IMN logo majestic logo threadwatch logo seochat tools logo