|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
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 07:01 PM. |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
||||
|
||||
|
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 ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Tkinter, Toplevel and grid |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|