SunQuest
           Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old December 8th, 2003, 06:58 PM
KalevTait KalevTait is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 2 KalevTait User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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 07:01 PM.

Reply With Quote
  #2  
Old December 9th, 2003, 05:44 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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


Reply With Quote
  #3  
Old December 9th, 2003, 12:10 PM
KalevTait KalevTait is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 2 KalevTait User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
  #4  
Old December 10th, 2003, 04:35 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Tkinter, Toplevel and grid


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway